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

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

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

问题

Desired output is:

  1. {
  2. "citycode": "34343",
  3. "branch": "cityname",
  4. "Marks": "L",
  5. "LANGUAGE-ID": "de",
  6. "Occupation": "security",
  7. "LANGUAGE-ID": "fr",
  8. "Occupation": "officer",
  9. "LANGUAGE-ID": "en",
  10. "Occupation": "superior"
  11. }

Current jolt output is below:

  1. {
  2. "citycode": "34343",
  3. "branch": "cityname",
  4. "Marks": "L",
  5. "LANGUAGE-ID": ["de", "fr", "en"],
  6. "Occupation": ["security", "officer", "superior"]
  7. }

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

英文:

I have below jolt input,

  1. {
  2. "citycode": "34343",
  3. "branch": "cityname",
  4. "changeDatetime": 1677063272522,
  5. "Marks": "L",
  6. "designations": [
  7. {
  8. "designation": "security ",
  9. "Language": "de"
  10. },
  11. {
  12. "designation": "officer",
  13. "Language": "fr"
  14. },
  15. {
  16. "designation": "superior",
  17. "Language": "en"
  18. }
  19. ]
  20. }

Desired output is:

  1. {
  2. "citycode" : "34343",
  3. "branch" : "cityname",
  4. "Marks" : "L",
  5. "LANGUAGE-ID" : "de",
  6. "Occupation" : "security",
  7. "LANGUAGE-ID" : "fr",
  8. "Occupation" : "officer",
  9. "LANGUAGE-ID" : "en",
  10. "Occupation" : "superior"
  11. }

current jolt output is below:

  1. {
  2. "citycode" : "34343",
  3. "branch" : "cityname",
  4. "Marks" : "L",
  5. "LANGUAGE-ID" : [ "de", "fr", "en" ],
  6. "Occupation" : [ "security ", "officer", "superior" ]
  7. }

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

答案1

得分: 2

以下是翻译好的部分:

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "*": "&", // 除了 "designations" 数组之外的所有元素
  6. "designations": {
  7. "*": { // 遍历 "designations" 数组的索引
  8. "L*": "LANGUAGE-ID_&1",
  9. "d*": "Occupation_&1"
  10. }
  11. }
  12. }
  13. }
  14. ]

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

英文:

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

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "*": "&", // all elements other than the "designations" array
  6. "designations": {
  7. "*": { // loop through the indexes of the "designations" array
  8. "L*": "LANGUAGE-ID_&1",
  9. "d*": "Occupation_&1"
  10. }
  11. }
  12. }
  13. }
  14. ]

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:

确定