Transforming JSON Structures with Java and JOLT
Sunday, January 29th, 2017When it comes to web-services (especially RESTful web-services), configuration files or other data-descriptors, the JavaScript Object Notation, short: JSON is often used as format of choice.
As the task arises to transform these JSON structures, I have seen a variety of different approaches from converting JSON into XML using JAX-B, applying XSLT, transforming into JSON again on the one hand to loading JSON structures into Hash-maps of Hash-maps (..) and manually removing single elements from these collections on the other hand.
JOLT is a library to make this task easier for us: It allows us to note down different types of transformations in a specification file in JSON syntax and to apply this specification to given JSON structures with ease.
In the following short tutorial I’d like to demonstrate how to use this library by transforming JSON structures programmatically with a few lines of code, by filtering a RESTful web-service using JOLT and a servlet filter and finally by adding a short example using the Apache Camel framework.