Pietro Fragnito
Pietro Fragnito

Reputation: 347

How to map entire JSON object as value into new JSON key using JOLT?

my goal is to map a JSON object into as value in a new JSON object key. Such as example:

My starting JSON:

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

My goal 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"
  }
}

How is it possible using JOLT: if I understand well I have to use a shift spec but I didn't understand how?

Can anyone can help me?

Thank you in advance

Upvotes: 0

Views: 365

Answers (1)

Magda
Magda

Reputation: 482

Wrapping into new object:

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

Upvotes: 3

Related Questions