m jsonq¶
Query json data.
single value::
m jsonq path.to.property < file.json
cat file.json | m jsonq path.to.property
m jsonq @file.json path.to.property
Return the value stored in the json file. For arrays and objects it will print the python representation of the object.
multiple values::
m jsonq path1 path2 path3 < file.json
cat file.json | m jsonq path1 path2 path3
m jsonq @file.json path1 path2 path3
use read
to store in bash variables::
read -r -d '\n' \
var1 var2 var3 \
<<< "$(m jsonq @file.json 'path1' 'path2' 'path3')"
If available, take advantage of better queries through jq and yq:
- jq: https://stedolan.github.io/jq/manual/
- yq: https://mikefarah.gitbook.io/yq/
Source code in m/cli/commands/jsonq.py
Options¶
-w
, --warn
¶
- default:
false
print warning messages instead of errors
-s
, --separator
¶
- default:
'\n'
separator for multiple values
Positional arguments¶
payload
¶
- default:
'@-'
json data: @- (stdin), @filename (file), string
query
¶
path to json data