小编Max*_*Max的帖子

使用jq获取特定键的所有父键

我想要做的是在我的 json 上“行走”,并为每个名为“base”的键添加一个键,该键是该键的完整“路径”。

这是我的 JSON:

{
  "entity": {
    "product": {
      "att": {
        "number_of_values": "Number of values"
      },
      "title": {
        "base": ["product", "products", "pdt", "pdts"]
      }
    },
    "rabbit": {
      "att": {
        "number_of_values": "Number of values"
      },
      "title": {
        "base": ["rabbit", "rabbits"]
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我想要这样的结果:

{
  "entity": {
    "product": {
      "att": {
        "number_of_values": "Number of values"
      },
      "title": {
        "base": ["product", "products", "pdt", "pdts"],
        "path": "entity.product.title"
      }
    },
    "rabbit": {
      "att": {
        "number_of_values": "Number of values"
      },
      "title": {
        "base": …
Run Code Online (Sandbox Code Playgroud)

json nested key path jq

5
推荐指数
1
解决办法
349
查看次数

标签 统计

jq ×1

json ×1

key ×1

nested ×1

path ×1