Spec-Zone.ru › Nushell

query json for filters

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

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.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/query_json.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API