【问题标题】:Compare and map values between two array of objects in JOLT比较和映射 JOLT 中两个对象数组之间的值
【发布时间】:2021-06-11 11:13:52
【问题描述】:

我需要根据 dataKey 值映射表头和行值。

输入 JSON

{
  "headers": [
    {
      "dataKey": "col-0",
      "displayName": "Product"
    },
    {
      "dataKey": "col-1",
      "displayName": "Dimension"
    },
    {
      "dataKey": "col-2",
      "displayName": "Output type "
    }
  ],
  "rows": [{
    "col-0": "Medium ",
    "col-1": "300x250",
    "col-2": "HTML [Animate]"
  }]
}

预期输出

{
  "Data" : {
    "1" : {
      "Product":"Medium",
      "Dimension":"300x250",
      "Output type":"HTML [Animate]"
    }
  }
}

规格:

这是我目前使用的 JOLT 规范,它没有产生预期的输出

[
  {
    "operation": "shift",
    "spec": {
      "headers": {
        "*": {
          "displayName": {
            "*": {
              "@(2,dataKey)": {
                "$": "Data.1.&",
                "*": {
                  "@(6,rows.&)": "Data.1.&"
                }
              }
            }
          }
        }
      }
    }
  }
]

请提供上述扫描仪的颠簸规格。我尝试了但无法获得预期的结果。

【问题讨论】:

  • @BarbarosÖzhan 我已经分离了颠簸规范和预期输出。

标签: json jolt


【解决方案1】:
[
  {
    // segregate values of the same key and form respective arrays.
    "operation": "shift",
    "spec": {
      "headers": {
        "*": {
          "displayName": "@(1,dataKey)"
        }
      },
      "rows": {
        "*": {
          "*": "&"
        }
      }
    }
  },
  {
    // put every value array into temp array
    "operation": "shift",
    "spec": {
      "*": "temp[]"
    }
  },
  {
    // map first index element as key and second index element as a value into the output
    "operation": "shift",
    "spec": {
      "temp": {
        "*": {
          "1": "Data.1.@(1,[0])"
        }
      }
    }
  }

]

【讨论】:

  • 完美解决阿伦!
  • 谢谢! Barbaros Özhan,您的赞赏对我来说真的很重要。
  • 谢谢,正如预期的那样工作 - @ArunSai
猜你喜欢
  • 2016-10-29
  • 2021-07-28
  • 1970-01-01
  • 2013-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多