简体   繁体   English

使用JOLT进行JSON到JSON的转换

[英]JSON to JSON transformation using JOLT

input 输入

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

} }

expected output: 预期输出:

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

Spec 规格

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

Updated Spec per comment, where Campus and Building should not be hard coded 更新了每个注释的规范,其中不应对校园和建筑物进行硬编码

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