jolt转换,同时使用if-else将键Map到新的键,并使用这些替换来替换新的键值对

uqzxnwby  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(549)

我需要对下面的json示例执行一个震动转换:

"treasure": [
  {
    "name": "FOO",
    "value": 45
  },
  {
    "name": "BAR",
    "value": 20
  },
  {
    "name":"FOOBAR",
    "value":23
]

我需要输出如下所示:

{
  "attributes" : {
    "RAB" : 20,
    "OOF" : 45,
    "RABOOF":23
   }

正如您所看到的,bar被rab替换,foo被oof替换,foobar被raboof替换也使用这个替换键来Map输入中的值。我需要使用if-else来替换键,并且在替换之后将值Map到相应的键这里的规范是什么?
这就是我达到的程度

{
"operation": "shift",
"spec": {
  "*": {
    "treasure": {
      "*": {
        "name":{
          "FOO":{
           "#OOF":"treasure.name"
         },
          "BAR":{
           "#RAB":"treasure.name"
         },
          "FOOBAR":{
           "#RABOOF":"treasure.name"
         }
       }

      }
    },
    "@(value)": "[&3].attributes.@(name)"
798qvoo8

798qvoo81#

检查一下这个规格,

[
  {
    "operation": "shift",
    "spec": {
      "treasure": {
        "*": {
          "name": {
            "FOO": {
              "#OOF": "treasure[&3].name",
              "@(2,value)": "treasure[&3].value"
            },
            "BAR": {
              "#RAB": "treasure[&3].name",
              "@(2,value)": "treasure[&3].value"
            },
            "FOOBAR": {
              "#RABOOF": "treasure[&3].name",
              "@(2,value)": "treasure[&3].value"
            }
          }
        }
      }
    }
  }, {
    "operation": "shift",
    "spec": {
      "treasure": {
        "*": {
          "@(0,value)": "attributes.@(1,name)"
        }
      }
    }
  }
]

相关问题