简体   繁体   English

JOLT: Make Nested 将嵌套数组作为主数组的一部分

[英]JOLT : Make Nested Make a nested array as part of main array

I am trying to transform the JSON as below expected output. Stuck with the spec below.我正在尝试将 JSON 转换为低于预期的 output。坚持下面的规范。 Can someone help in this?有人可以帮忙吗?

There is an inner array with name "content" in the "results" array which I want to make it as a part of main array. “结果”数组中有一个名为“内容”的内部数组,我想将其作为主数组的一部分。

Input JSON输入 JSON

{
  "total": 100,
  "start": 1,
  "page-length": 10,
  "results": [
    {
      "index": 1,
      "uri": "uri1/uri2",
      "extracted": {
        "kind": "object",
        "content": [
          {
            "code": "A1",
            "region": "APAC"
          }
        ]
      }
    },
    {
      "index": 2,
      "uri": "uri1/uri2",
      "extracted": {
        "kind": "object",
        "content": [
          {
            "code": "B1",
            "region": "AMER"
          }
        ]
      }
    },
    {
      "index": 3,
      "uri": "uri1/uri2",
      "extracted": {
        "kind": "object",
        "content": [
          {
            "code": "C1",
            "region": "APAC"
          }
        ]
      }
    }
  ]
}

Expected json output预计 json output

[
  {
    "code": "A1",
    "region": "APAC"
  },
  {
    "code": "B1",
    "region": "AMER"
  },
  {
    "code": "C1",
    "region": "APAC"
  }
]

Spec Tried试过规格

[
  {
    "operation": "shift",
    "spec": {
      "results": {
        "*": {
          "extracted": { "content": { "@": "&" } }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "content": {
        "@": "&"
      }
    }
  }

]

Find the output below I am getting on Jolt tool在下面找到我正在使用 Jolt 工具的 output 在此处输入图像描述

You can use # wildcard nested within square brackets in order to reach the level of the indexes of the "results" array such that您可以使用嵌套在方括号内的#通配符来达到"results"数组的索引级别,这样

[
  {
    "operation": "shift",
    "spec": {
      "results": {
        "*": {//the indexes of the "results" array
          "extracted": {
            "content": {
              "*": {//the indexes of the "content" array
                "*": "[#5].&"
              }
            }
          }
        }
      }
    }
  }
]

Also the following spec, which repeats the content of the inner array without keys, will give the same result:此外,以下规范重复了没有键的内部数组的内容,将给出相同的结果:

[
  {
    "operation": "shift",
    "spec": {
      "results": {
        "*": {
          "extracted": {
            "content": {
              "*": "[]"// [] seems like redundant but kept for the case the array has a single object.
            }
          }
        }
      }
    }
  }
]

which is quite similar to your tried one.这与您尝试过的非常相似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM