I wanted to use python return /sys.exit value as variable for further processing.
#!/bin/bash
cat myjson.json | \
output=($(python -c 'import json,sys;obj=json.load(sys.stdin);
result =[];
for y in [x["_source"]["memberId"] for x in obj["hits"]["hits"]]:
result+=[y];
sys.exit(result)'))
echo 'output'$output
what is the best approach to read JSON data in the shell script using Python and store the Python output in an array variable of shell script
sys.exit()can only return integer values. If you want json, that will have to be printed as regular output. Or written to a file, saved to a database, etc.jqorxmlstarletspecializing in their handling while being intentionally easy to use from scripts.