0

我需要使用 jolt 转换 JSON。输入JSON如下:

 {
  "items": [
    {
      "Group1": {
        "ABCCode": "3",
        "ABCDescription": "abcd"
      },
      "Group2": {
        "test2": [
          "123"
        ]
      }
    }
  ]
}

我需要如下输出,

[
   {
      "test2Id": "123",
      "attrname": "ABCCode",
      "attrval": "3"
   },
   {
      "test2Id": "123",
      "attrname": "ABCDescription",
      "attrval": "abcd"
   }
]

如何使用 jolt 实现这一目标?

4

1 回答 1

0

这会从给定的输入产生输出。你可能需要调整它,因为你给它不同类型的输入。

[
  {
    "operation": "shift",
    "spec": {
      "items": {
        "*": {
          "Group1": {
            // match all keys below Group1
            "*": {
              // "$" means grab the key matched above, 
              //   and write it the the output as "attrname"
              "$": "[#2].attrname",
              // "@" means grab the value matched above
              "@": "[#2].attrval",
              // walk back up the match tree three levels
              //  walk back down the path "Group2.test2[0]"
              //  and write that value to the output
              "@(2,Group2.test2[0])": "[#2].test2Id"
            }
          }
        }
      }
    }
  }
]
于 2018-02-22T11:20:47.063 回答