【问题标题】:show structure of all levels of json with jq and bash使用 jq 和 bash 显示所有级别的 json 结构
【发布时间】:2016-07-28 07:52:55
【问题描述】:

如何列出所有级别和数组属性的 json 文件的所有唯一键及其路径?

我找到了 jq -s 'map(keys) |添加 |独一无二 | sort' input.json,但这只列出了第一级,没有路径。

【问题讨论】:

  • 您可以提供一个示例 json 文件。

标签: json bash structure jq datamodel


【解决方案1】:

如果您将输入流式传输,它将为您提供输入中包含的路径和值对。

$ jq --stream 'select(length>1)[0]' input.json

所以对于这样的输入:

{
  "foo": { "bar": 1 },
  "biz": { "baz": 2 }
}

你会得到:

[
  "foo",
  "bar"
]
[
  "biz",
  "baz"
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多