簡體   English   中英

使用JOLT進行JSON到JSON的轉換

[英]JSON to JSON transformation using JOLT

輸入

{
"ances": [
    {
        "id": 1,
        "level": "Building",
        "name": " Metro Campus Outdoor"
    },
    {
        "id": 2,
        "level": "Campus",
        "name": " Metro Campus"
    }
]

}

預期輸出:

{
  "result": [
    {
      "Building_id": 1,
      "Building": "my building for Outdoor"
    },
    {
      "Building_id": 2,
      "Campus": "Man Metro Campus"
    }
  ]
}


i want to change the name key with the value of the level tag.

規格

[
  {
    "operation": "shift",
    "spec": {
      "ances": {
        "*": {
          "id": "result[&1].Building_id",
          "level": {
            "Building": {
              // if we matched all the way down here
              // then go back up and grab the "name" 
              // and write it's value to Building in
              // the result
              "@(2,name)": "result[&3].Building"
            },
            "Campus": {
              "@(2,name)": "result[&3].Campus"
            }
          }
        }
      }
    }
  }
]

更新了每個注釋的規范,其中不應對校園和建築物進行硬編碼

[
  {
    "operation": "shift",
    "spec": {
      "ances": {
        "*": {
          "id": "result[&1].Building_id",
          "level": {
            "*": {
              // if we matched all the way down here
              // then go back up and grab the "name" 
              // and write it's value to 
              // the result array, using the value of 
              //  level as the key
              "@(2,name)": "result[&3].&1"
            }
          }
        }
      }
    }
  }
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM