Spec-Zone.ru › Nushell

query json для фильтров

выполнить запрос json к файлу json (open --raw <file> | query json 'query string')

Сигнатура

> query json {flags} (query)

Параметры

  • query: Запрос Json.

Примеры

Получить список дочерних элементов объекта json

> '{"children": ["Sara","Alex","Jack"]}' | query json children
╭───┬──────╮
│ 0 │ Sara │
│ 1 │ Alex │
│ 2 │ Jack │
╰───┴──────╯

Получить список имён друзей из объекта json

> '{
  "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  │
╰───┴───────╯

Получить ключ last имени из объекта json

> '{"name": {"first": "Tom", "last": "Anderson"}}' | query json name.last
Anderson

Получить количество дочерних элементов объекта json

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

Получить первый дочерний элемент массива children в обратном порядке с помощью модификатора @reverse из объекта json

> '{"children": ["Sara","Alex","Jack"]}' | query json "children|@reverse|0"
Jack

Примечания

query json использует crate gjson https://github.com/tidwall/gjson.rs для выполнения запросов к данным json.

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