query json for filters
execute json query on json file (open --raw <file> | query json 'query string')
This command requires a plugin
The query json command resides in the query plugin. To use this command, you must install and register nu_plugin_query. See the Plugins chapter in the book for more information.
Signature
> query json {flags} (query)
Parameters
query: json query
Examples
Get a list of children from a json object
> '{"children": ["Sara","Alex","Jack"]}' | query json children
╭───┬──────╮
│ 0 │ Sara │
│ 1 │ Alex │
│ 2 │ Jack │
╰───┴──────╯Get a list of first names of the friends from a json object
> '{
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
]
}' | query json friends.#.first
╭───┬───────╮
│ 0 │ Dale │
│ 1 │ Roger │
│ 2 │ Jane │
╰───┴───────╯Get the key named last of the name from a json object
> '{"name": {"first": "Tom", "last": "Anderson"}}' | query json name.last
AndersonGet the count of children from a json object
> '{"children": ["Sara","Alex","Jack"]}' | query json children.#
3Get the first child from the children array in reverse the order using the @reverse modifier from a json object
> '{"children": ["Sara","Alex","Jack"]}' | query json "children|@reverse|0"
JackNotes
query json uses the gjson crate https://github.com/tidwall/gjson.rs to query json data.