JSON to JSON transformer

Try JOLT. It is a JSON to JSON transformation library written in Java. It was created on a project that was transforming lot of JSON from an ElasticSearch "backend" to a frontend api.

For the JSON transform you have listed in your problem, the Jolt "shift" spec would be :

// Jolt "shift" spec
{
    "OldObject": {
        "Time": "NewObject.Time",   
        "Name": "NewObject.Title", // if the input has "OldObject.Name", copy it's value
                                   // to "NewObject.Title
        "quantity": "NewObject.quantity"
    }
}

You can try jmom a little java library

String jsonstring = "...";
JsonValue json = JsonParser.parse(jsonstring);
Jmom jmom = Jmom.instance()
            .copy("/OldObject", "/NewObject", true)
            .remove("/NewObject/price")
            .copy("/NewObject/Name", "/NewObject/Title", true);
jmom.apply(json);
jsonstring = json.toCompactString();

You can use ZORBA and JsonIQ http://www.jsoniq.org/ However, it's a native library, it comes with a wrapper so you can use it in java.


You can do this transformation with JSON patch.

Example with jsonpatch-js:

var transformations = [
  { move: '/OldObject', to: '/NewObject' },
  { remove: '/NewObject/price' },
  { move: '/NewObject/Name', to: '/NewObject/Title' }
];

var oldObject = { "OldObject": { "Time": 1351160457922, "Name": "OName", "quantity": 100, "price": 10 } };

jsonpatch.apply(oldObject, transformations);

I did not test the provided, but should work like that.

There are Java implementations for JSON patch: