Jolt Processor
Jolt processor changes the way data is organized in JSON files without changing the actual data inside them, using special languages for these changes.
Jolt processor is used for performing a JSON to JSON transformations in Java.
It applies transformation on Input JSON document and generates a new JSON document as per the user-defined Jolt specifications.
Refer to the following links for detailed information:
Processor Configuration
A Jolt Specification JSON should be provided to the Jolt Processor explaining how to transform input data into the desired output format.
It should contain rules that specify which fields to use, how to manipulate them, and where to put the results in the output data.
Enter or upload specification JSON
You can either enter the specification details in JSON format or upload a JSON file that already has the required specifications in it.
The content of the specification JSON file gets displayed in the box below the upload option.
This specification gets applied on incoming json document and generates the transformed output.
Add Configuration: Additional properties can be added using ADD CONFIGURATION link.
Transforming JSON Data with the Jolt Processor: An Example
Step 1. Provide sample data in JSON format using the file upload data source.
Sample input schema:
{
"x": [3, 2, 1, 4],
"small": "small_letters",
"BIG": "BIG_LETTERS",
"people": [
{"firstName": "Bob", "lastName": "Smith"},
{"firstName": "Sterling", "lastName": "Archer"}
]
}
Input schema validated in Gathr:
The sample JSON schema represents the following:
x contains an array of numbers: [3, 2, 1, 4].
small is a text field with the value “small_letters”.
BIG is another text field with the value “BIG_LETTERS”.
people is an array containing information about two individuals:
Person 1: firstName is “Bob” and lastName is “Smith”.
Person 2: firstName is “Sterling” and lastName is “Archer”.
Step 2. Connect a Jolt processor to the File data source and provide the specifications to transform the incoming schema.
Specifications provided to Jolt processor:
[
{
"operation": "modify-default-beta",
"spec": {
"y": "=join(',',@(1,x))",
"z": "=join(' ',@(1,x))",
"small_toUpper": "=toUpper(@(1,small))",
"BIG_toLower": "=toLower(@(1,BIG))",
"people": {
"*": {
"fullName": "=concat(@(1,firstName),' ',@(1,lastName))"
}
}
}
}
]
Specifications uploaded in Jolt processor:
The specifications represent the following:
“y” and “z” Fields:
y should be created by joining the values from the x array with commas.
z should be created by joining the values from the x array with spaces.
“small_toUpper” Field:
- Convert the small field to uppercase and place the result in the small_toUpper field.
“BIG_toLower” Field:
- Convert the BIG field to lowercase and place the result in the BIG_toLower field.
“people” Field:
For each person object in the people array:
- Create a fullName field by concatenating the firstName and lastName fields with a space in between.
Step 3. Continue to configure the Jolt processor.
After applying the Jolt specifications to the input JSON, you’ll get a modified JSON with the additional fields as specified.
You can see the Input Data, Jolt Specification, and the Output Data during the application’s design phase.
The resulting JSON data should have these additional fields and transformations:
y and z fields based on the x array.
small_toUpper field with the small field in uppercase.
BIG_toLower field with the BIG field in lowercase.
fullName fields for each person in the people array, combining firstName and lastName fields.
The output of the Jolt Processor will be in JSON format, which can represent complex data structures.
You can further simplify the output if needed or save it to a preferred emitter.
If you want to further simplify or flatten this data for your use case, you can use a Field Flattener processor.
This processor can take the complex JSON structure and transform it into a simpler format.
For example, after applying a Field Flattener, the output might look like this:
This flattened format reduces the complexity of the data structure and makes it easier to work with.
If you have any feedback on Gathr documentation, please email us!