首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用jolt递归迭代标记

如何使用jolt递归迭代标记
EN

Stack Overflow用户
提问于 2018-02-21 18:14:48
回答 1查看 735关注 0票数 0

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

代码语言:javascript
复制
 {
  "items": [
    {
      "Group1": {
        "ABCCode": "3",
        "ABCDescription": "abcd"
      },
      "Group2": {
        "test2": [
          "123"
        ]
      }
    }
  ]
}

我需要如下的输出,

代码语言:javascript
复制
[
   {
      "test2Id": "123",
      "attrname": "ABCCode",
      "attrval": "3"
   },
   {
      "test2Id": "123",
      "attrname": "ABCDescription",
      "attrval": "abcd"
   }
]

如何使用jolt实现这一点?

EN

回答 1

Stack Overflow用户

发布于 2018-02-22 19:20:47

这将从给定的输入中产生输出。您可能需要调整它,因为您为它提供了不同类型的输入。

代码语言:javascript
复制
[
  {
    "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"
            }
          }
        }
      }
    }
  }
]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48903290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档