query json

For filters.

execute json query on json file (open --raw <file> | query json 'query string')

warning 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.

Command Type

plugin

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
Anderson

Get the count of children from a json object

> '{"children": ["Sara","Alex","Jack"]}' | query json children.#
3

Get 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"
Jack

Notes

query json uses the gjson crate https://github.com/tidwall/gjson.rs to query json data.

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.