简体   繁体   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

I need to perform a Jolt transformation on the below example json:我需要对以下示例 json 执行颠簸转换:

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

I need the output to look like:我需要 output 看起来像:

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

as you can see the BAR is replaced with RAB, FOO with OOF and FOOBAR replaced with RABOOF also used this replacement keys to map with the values in the input.如您所见,BAR 被 RAB 替换,FOO 被 OOF 替换,FOOBAR 被 RABOOF 替换,也使用了 map 的替换键和输入中的值。 I need to use a IF ELSE to make the replacement of the keys and also after replacing map the values to the keys accordingly What should be the spec here?我需要使用 IF ELSE 来替换键,并且在替换 map 之后,相应地键的值应该是什么?

This is how far I reached这就是我达到的程度

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


  

Check this spec,检查这个规格,

[
  {
    "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.

相关问题 使用 Jolt 对键进行 JSON 到 JSON 转换 - JSON to JSON transformation on keys using Jolt 使用put存储新的键值对时,现有键的Hashmap值会被覆盖。 怎么预防呢? - Hashmap values of existing keys getting overwritten upon using put to store a new key-value pair. how to prevent it? 修改值后键值对的颠簸转换规范 - Jolt transformation spec for the key Value pair after modifying values 添加新的键值对会在 HashMap 中替换其他键的值 - Adding new key-value pair gets other keys' values replaced in HashMap 如果键上有其他条件,则颠簸变换? - Jolt Transform If Else Condition on keys? RestTemplate映射带有动态键的JSON键-值对对象 - RestTemplate map JSON key-value pair object with with dynamic keys 使用流根据键在键值对上应用不同的功能 - Using streams to apply different functions on key value pair depending on keys 拆分地图的键,并使用新键和关联值创建一个新地图 - Split the keys of a Map and create a new Map with the new keys and the associated values 如何将新的键值对放入DynamoDB中的地图中? (Java)的 - How to put a new key-value pair into a map in DynamoDB? (java) 创建一个地图/缓存,它将默认构造函数生成的对象用于新键 - Create a map/cache that will use objects generated by the default constructor for new keys
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM