bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

Copy value from one key to a sub object #1057

Open pravesh-curefit opened 3 years ago

pravesh-curefit commented 3 years ago

Input

{
        "id": 1,
    "name": "Sample name",
    "attributes": {
        "age": 10
    }
}

Output

{
        "id": 1,
    "attributes": {
        "name": "Sample name",
        "age": 10
    }
}

I want to carry out this transformation. I tried with the below spec

[
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "name": "attributes.&"
    }
  }
]

But this changes attributes field into an array. What should be the right spec used here?

denoenu commented 3 years ago

does this help

[

{ "operation": "shift", "spec": { "id": "id", "attributes": { "@(1,name)": "attributes.name", "age": "attributes.age" } } } ]

kunal15112001 commented 1 year ago

[ { "operation": "shift", "spec": { "id": "id", "attributes": { "@(1,name)": "attributes.name", "age": "attributes.age" } } } ]