bazaarvoice / jolt

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

Convert list of objects into a map of multiple entries #993

Open tejpalborkar opened 4 years ago

tejpalborkar commented 4 years ago

I am trying to convert below json object into the below-expected output, but somehow I am ending up in getting the array Input Json:

{
  "tags":{
    "list":[
      {
        "TagSimple":{
          "name":"Tag1",
          "id":"id1"
        }
      },
      {
        "TagSimple":{
          "name":"Tag2 ",
          "id":"Id2"
        }
      }
    ]
  }
}

Expected output:

{
  "sourceTags":{
    "Id1":"Tag1",
    "id2":"Tag2"
  }
}

sourceTags I should be able to convert resulting json to the java map. Here is the jolt spect I am trying to using

[
  {
    "operation":"shift",
    "spec":{
      "tags":{
        "list":{
          "*":{
            "TagSimple":{
              "name":"sourceTags.&1.name",
              "id":"sourceTags.&1.id"
            }
          }
        }
      }
    }
  }
]
rjspotter commented 4 years ago

Did you ever figure out a way to resolve this?