簡體   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