繁体   English   中英

使用 IF ELSE map 将键转换为新键,并将这些替换用于新键值对

[英]Jolt transformation while using IF ELSE map the keys to new keys and also use these replacement for new key value pair

我需要对以下示例 json 执行颠簸转换:

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

我需要 output 看起来像:

  {
  "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)"


  

检查这个规格,

[
  {
    "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)"
        }
      }
    }
  }
]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM