One frequent use case most of the Adobe Experience Manager (AEM) Full Stack Developers would have come across is migrating content from different applications into AEM. Data from source applications can come in various formats like JSON, XML, CSV, etc. When the source file format is JSON, in order to transform the source data to target structure, we need to write complex programs to read and parse it. In this blog, I will show you an efficient and configurable solution to this problem.
I recently faced this challenge with one of our clients. They have a Solr service, in which the most recent information about their shops around the world is stored. I wanted to avoid calling that service every time we present that information in AEM. For this purpose, I decided to implement a daily batch process to get the data from the service and turn it into JCR nodes and properties.
The problem was that the information is stored in a format that does not directly match the structure required for shop pages in our current AEM implementation. Therefore, I needed to perform a transformation of that data before uploading it to the system.
My first thought was to write an elaborate transformation algorithm. Nevertheless, I realized that this probably was a pretty common problem and decided to look for a library to do the job. The best option I found was Jolt. It is an open-source library with zero external dependencies, tested in several other open-source projects like Apache Camel and Apache NiFi, and highly discussed in software development forums.
What is Jolt?
Jolt is an open-source JSON to JSON transformation library written in Java.
Jolt’s main features are:
Provides a set of transformations to deal with the JSON-to-JSON conversion.
Transforms the structure of the JSON data, not data manipulation.
Uses a JSON file for the specification.