使用JOLT进行JSON到JSON转换

时间:2017-07-26 08:43:04

标签: json 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.

1 个答案:

答案 0 :(得分:0)

规格

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