bazaarvoice / jolt

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

JSON Transformation: want help to start the array index from 1 , looking for Jolt Spec #1186

Open HarithaKoritala opened 1 year ago

HarithaKoritala commented 1 year ago

I have input like below { "employees": [ {"name":"", "salary":"salary1"}, {"name":"emp2", "salary":"salary2"}, {"name":"empn","salary":"salaryn"} ] } this need to be transformed like { "employees": { "employee1":"salary1", "employee2":"salalry2","employeen":"salaryn"} }

I tried the below jolt spec to transform but index is started from 0 index instead of 1

{ "operation":"shift", "spec":{ "employees":{ "*": { "salary":"employees.employee&1"} }} }

This gave result like { "employees": { "employee0":"salary1", "employee1":"salalry2","employeen":"salaryn" } }

How can i manage to produce the result in proper way , Can anyone please help me with this...

gawhadebhavna commented 1 year ago

Hi @HarithaKoritala

You can use the below spec

[
  {
    "operation": "shift",
    "spec": {
      "employees": {
        "*": {
          "salary": {
            "*y*": {
              "@1": "&4.employee&(0,2)"
            }
          }
        }
      }
    }
  }
]
AndrewKZY commented 1 year ago

hello i am curious on the spec can u explain these 2 "y : { "@1": "&4.employee&(0,2)"