【问题标题】:Flatten JSON array in Jolt Transform在 Jolt Transform 中展平 JSON 数组
【发布时间】:2019-10-11 12:59:26
【问题描述】:

输入:

[
  {
    "name": "Foo",
    "ratings": [
      {
        "value": 2
      },
      {
        "value": 4
      }
    ]
  }
]

规格:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "ratings": {
          "@": ""
        }
      }
    }
  }
]

输出:

[ {
  "value" : 2
}, {
  "value" : 4
} ]

我想要达到的目标:

[ {
  "name": "Foo",
  "value" : 2
}, {
  "name": "Foo",
  "value" : 4
} ]

任何想法如何修改我的 jolt 规范以实现该输出?

【问题讨论】:

    标签: jolt


    【解决方案1】:
    [
      {
        "operation": "shift",
        "spec": {
          "*": { // top level array
            "ratings": {
              "*": { // ratings array
                // push name down, but maintain the 
                //  same doubly nested array structure
                "@(2,name)": "[&3].[&1].name",
                // copy everything inside a ratings document 
                "*": "[&3].[&1].&"
              }
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": { // top level array
            // 2nd level array
            "*": "[]"
          }
        }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-06
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多