bazaarvoice / jolt

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

Adding a property between other properties in a JSON object #1221

Open estigma88 opened 1 year ago

estigma88 commented 1 year ago

Hi everyone, I would like to add a property between other properties in a JSON object.

Input:

{
  "f1": "v1",
  "f3": "v3"
}

Expected output:

{
  "f1": "v1",
  "f2": "v2",
  "f3": "v3"
}

The original JSON should be kept as it is. Also, this case could go beyond, for instance, trying to add a new property in the third position, as follows:

Input:

{
  "f1": "v1",
  "f2": "v2",
  "f3": "v3"
}

Output:

{
  "f1": "v1",
  "f2": "v2",
  "f2.1": "v2.1",
  "f3": "v3"
}

There, the property f2.1 was added as 3th element in the JSON object.

Not sure how to build a JOLT transformation for that, so, any help would be appreciated.