显示从在Jolt Transform中展平的对象数组中获取的属性。

huangapple go评论62阅读模式
英文:

To Display the attributes, which are taken from the array of objects, flattened in Jolt Transform

问题

Desired output is:

{
  "citycode": "34343",
  "branch": "cityname",
  "Marks": "L",
  "LANGUAGE-ID": "de",
  "Occupation": "security",
  "LANGUAGE-ID": "fr",
  "Occupation": "officer",
  "LANGUAGE-ID": "en",
  "Occupation": "superior"
}

Current jolt output is below:

{
  "citycode": "34343",
  "branch": "cityname",
  "Marks": "L",
  "LANGUAGE-ID": ["de", "fr", "en"],
  "Occupation": ["security", "officer", "superior"]
}

Need to split the array elements separately. Can you please help?

英文:

I have below jolt input,

{
  "citycode": "34343",
  "branch": "cityname",
  "changeDatetime": 1677063272522,
  "Marks": "L",
  "designations": [
    {
      "designation": "security ",
      "Language": "de"
    },
    {
      "designation": "officer",
      "Language": "fr"
    },
    {
      "designation": "superior",
      "Language": "en"
    }
  ]
}

Desired output is:

{
  "citycode" : "34343",
  "branch" : "cityname",
  "Marks" : "L",
  "LANGUAGE-ID" :  "de", 
  "Occupation" : "security",
  "LANGUAGE-ID" :  "fr",
  "Occupation" : "officer",
  "LANGUAGE-ID" : "en",
  "Occupation" : "superior"
}

current jolt output is below:

{
  "citycode" : "34343",
  "branch" : "cityname",
  "Marks" : "L",
  "LANGUAGE-ID" : [ "de", "fr", "en" ],
  "Occupation" : [ "security ", "officer", "superior" ]
}

Need to split the array elements separately.
Can you please help

答案1

得分: 2

以下是翻译好的部分:

[
  {
    "operation": "shift",
    "spec": {
      "*": "&", // 除了 "designations" 数组之外的所有元素
      "designations": {
        "*": { // 遍历 "designations" 数组的索引
          "L*": "LANGUAGE-ID_&1",
          "d*": "Occupation_&1"
        }
      }
    }
  }
]

此输出会为每个 LANGUAGE-IDOccupation 键添加递增的索引(0、1、2)。

英文:

The current desired JSON output is invalid, but presumably you need the following one

[
  {
    "operation": "shift",
    "spec": {
      "*": "&", // all elements other than the "designations" array
      "designations": {
        "*": { // loop through the indexes of the "designations" array
          "L*": "LANGUAGE-ID_&1",
          "d*": "Occupation_&1"
        }
      }
    }
  }
]

which suffixes incremental(0,1,2) indexes per each LANGUAGE-ID and Occupation key

huangapple
  • 本文由 发表于 2023年7月23日 20:59:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76748366.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定