如何使用JOLT将整个JSON对象作为值映射到新的JSON密钥中?

时间:2019-05-27 10:27:48

标签: json jolt

我的目标是将JSON对象映射为新JSON对象密钥中的值。例如:

我的起始JSON:

{
 "old_key_1" : "some_json_structure_1",
 "old_key_2" : "some_json_structure_2",
 "old_key_3" : "some_json_structure_3"
}

我的目标JSON:

{
 "new_key_1" : 
  {
    "old_key_1" : "some_json_structure_1",
    "old_key_2" : "some_json_structure_2",
    "old_key_3" : "some_json_structure_3"
  }
}

使用JOLT怎么可能:如果我了解得很清楚,我必须使用换档规范,但我不知道如何?

任何人都可以帮助我吗?

提前谢谢

1 个答案:

答案 0 :(得分:1)

包装到新对象中

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "new_key_1.&" //the "&" means go up the tree 0 levels, grab what is there and subtitute it in
      }
    }
  }
]