挣扎与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(' ',values))"
        }
      }
    }
  },{
    "operation": "shift","spec": {
      "records": {
        "*": {
          "counters": { "*": "counters[]" },"values": { "*": "values[]" }
        }
      }
    }
  },{ // ...concat() must instead of toUpper...
    "operation": "modify-overwrite-beta","spec": {
      "counters": {
        "*": "=toUpper"
      }
    }
  },"spec": {
      "counters": {
        "*": {
          "*": {
            "@(3,values[#2])": "&"
          }
        }
      }
    }
  }
]

但无法完成最后一步-尝试所有选项,但是concat返回“ x”或ItemX,但不返回xItemX ...

谢谢

fishin8 回答:挣扎与JOLT concat

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

[
  {
    "operation": "modify-overwrite-beta","spec": {
      "records": {
        "*": {
          "counters": "=split(' ',@(1,counters))","values": "=split(' ',values))"
        }
      }
    }
  },{
    "operation": "shift","spec": {
      "records": {
        "*": {
          "counters": { "*": "counters[]" },"values": { "*": "values[]" }
        }
      }
    }
  },{ 
    "operation": "modify-overwrite-beta","spec": {
      "counters": {
        "*": "=toUpper"
      }
    }
  },"spec": {
      "counters": {
        "*": {
          "*": {
            "@(3,values[#2])": "x&"
          }
        }
      }
    }
  }
]
本文链接:https://www.f2er.com/2719927.html

大家都在问