与 JOLT concat 作斗争

Struggling with JOLT concat

我正在努力使用 JOLT 进行转换。

输入:

{
  "records": [
    {"counters": "Item1 Item2 Item3 Item4 Item5 Item6",
      "values": "V1 V2 V3 V4 V5 V6"},
    {"counters": "Item7 Item8 Item9 Item10 Item11",
      "values": "V7 V8 V9 V10 V11"},
    {"counters": "Item12 Item13",
      "values": "V12 V13"},
    {"counters": "Item14",
      "values": "V14"}
  ]
}

期望的输出:

{
  "xItem1" : "V1",
  "xItem2" : "V2",
  "xItem3" : "V3",
  "xItem4" : "V4",
  "xItem5" : "V5",
  "xItem6" : "V6",
  "xItem7" : "V7",
  "xItem8" : "V8",
  "xItem9" : "V9",
  "xItem10" : "V10",
  "xItem11" : "V11",
  "xItem12" : "V12",
  "xItem13" : "V13",
  "xItem14" : "V14"
}

我几乎已经用这个震动完成了它(通过将 toUpper 步骤替换为添加所需 "x" 的步骤):

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "records": {
        "*": {
          "counters": "=split(' ',@(1,counters))",
          "values": "=split(' ',@(1,values))"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "records": {
        "*": {
          "counters": { "*": "counters[]" },
          "values": { "*": "values[]" }
        }
      }
    }
  },
  { // ...concat() must instead of toUpper...
    "operation": "modify-overwrite-beta",
    "spec": {
      "counters": {
        "*": "=toUpper"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "counters": {
        "*": {
          "*": {
            "@(3,values[#2])": "&"
          }
        }
      }
    }
  }
]

但无法完成最后一步 - 尝试所有选项,但连接 returns "x" 或 ItemX,但不连接 xItemX...

谢谢

不确定这是否是您所需要的,但您真的不需要使用 concat 将 x 添加到属性名称,只需将 x 添加到规则后跟 &:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "records": {
        "*": {
          "counters": "=split(' ',@(1,counters))",
          "values": "=split(' ',@(1,values))"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "records": {
        "*": {
          "counters": { "*": "counters[]" },
          "values": { "*": "values[]" }
        }
      }
    }
  },
  { 
    "operation": "modify-overwrite-beta",
    "spec": {
      "counters": {
        "*": "=toUpper"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "counters": {
        "*": {
          "*": {
            "@(3,values[#2])": "x&"
          }
        }
      }
    }
  }
]