【问题标题】:Need Jolt Spec to convert matrix json to denormalized json formart需要 Jolt Spec 将矩阵 json 转换为非规范化 json 格式
【发布时间】:2021-06-07 04:50:09
【问题描述】:

谁能帮我一个JOLT规范将我的矩阵类型json转换为非规范化json。请在下面找到我的输入 json 和我预期的 josn 输出。

输入 Json:

[
  {
    "attributes": [
      {
        "name": "brand",
        "value": "Patriot Lighting"
      },
      {
        "name": "color",
        "value": "Chrome"
      },
      {
        "name": "price",
        "value": "49.97 USD"
      }
    ]
  },
  {
    "attributes": [
      {
        "name": "brand",
        "value": "Masterforce"
      },
      {
        "name": "color",
        "value": "Green"
      },
      {
        "name": "price",
        "value": "99.0 USD"
      }
    ]
  }
]

预期的 Json 输出:

  [
    {
      "brand": "Patriot Lighting",
      "color": "Chrome",
      "price": "49.97 USD"
    },
    {
      "brand": "Masterforce",
      "color": "Green",
      "price": "99.0 USD"
    }
  ]

我试图构建 JOLT 规范来转换这个 json。但挑战是我有多个带有“属性”标签的表的 json。

提前致谢!

【问题讨论】:

    标签: json jolt denormalization jsonconverter


    【解决方案1】:

    JOLT 不容易使用,但我从其他一些 StackOverflow 问题中得到了很多,我刚开始阅读 the source code comments

    [
      {
        "operation": "shift",
        "spec": {
          // for each element in the array
          "*": {
            "attributes": {
              // for each element in the attribute
              "*": {
                // grab the value
                // - put it in an array
                //   - but it must be indexed by the "positions" found four steps back
                // - put the value in a key
                //   - that is determined by moving one step back and looking at member name
                "value": "[#4].@(1,name)"
              }
            }
          }
        }
      }
    ]
    

    乍一看这似乎很模糊,但我希望 cmets 解释一切。

    请继续阅读JOLT transformation to copy single value along an array

    这对于 JOLT 初学者来说几乎是强制性的https://docs.google.com/presentation/d/1sAiuiFC4Lzz4-064sg1p8EQt2ev0o442MfEbvrpD1ls/edit#slide=id.g9a487080_011

    如果你需要另一个例子,我只是在这里回答了一个问题Nifi JOLT: flat JSON object to a list of JSON object

    而且,您最好的朋友可能在https://jolt-demo.appspot.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多