I'm trying to write a shell script where I parse some JSON. Specifically, I want to extract the value of an "id" element. I have the below (I have Python 3 installed on my system) ...
user_json=$(curl --header "Content-type: application/json" -H "Authorization: Bearer $json_token" --data "$req" --request POST "$URL/mypath")
echo $user_json
user_id=$(echo $user_json | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["id"])')
echo $user_id
However the above results in a
/opt/scripts/sync_script.sh: line 36: /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/python: cannot execute binary file
on the "python" line (the $user_id var is never printed). What else do I need to do to get this working? When the $user_json is printed out, I can clearly see the "id" value ...
{"id":"4b8d53a5-d0b5-4175-82ec-8aeda435ba62","first_name":"ddd"}
Edit: In response to comments, I get the below error when attempting to see the version of my Python. Permissions are included as well.
localhost:tmp davea$ /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/python -version
-bash: /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/python: cannot execute binary file
localhost:tmp davea$ ls -al /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/python
-rwxr-xr-x 1 davea admin 2382880 Apr 16 2019 /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/python