需要 Jolt Spec 将矩阵 json 转换为非规范化 json 格式

Need Jolt Spec to convert matrix json to denormalized json formart

任何人都可以帮我 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,我有多个带有“属性”标签的表。

提前致谢!

JOLT 不容易使用,但我从其他一些 Whosebug 问题中得到了很多,我刚刚开始阅读 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)"
          }
        }
      }
    }
  }
]

乍一看这似乎很晦涩,但我希望评论能解释一切。

请继续阅读

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

如果你需要另一个例子,我刚刚在这里回答了一个问题

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

找到