I am new to jolt transformation. what would be the jolt spec to transform my source json
{
"version": "123",
"payload": {
"details": {
"payload_json": "{"FName":"rishi","LName":"dx","Id":"ABC123","aadharId":"XYZ22"}"
}
}
}
to target JSON
{
"firstName": "rishi",
"lastName": "dx",
"id": "ABC123",
"officialIds": [
{
"type": "aadhar",
"value": "XYZ22"
}
]
}
I tried using Google Gemini and Micosoft Copilot to get the jolt spec, but neither of them are generating correct spec.
2
Answers
To achieve your desired transformation using Jolt, you can use a combination of shift and modify transformation steps. Here’s the Jolt spec to transform your source JSON to the target JSON:
[
{
"operation": "shift",
"spec": {
"payload": {
"details": {
"payload_json": {
"*": {
// Move all fields from payload_json to the top level
"@": "&"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
// Rename fields according to the target structure
"FName": "firstName",
"LName": "lastName",
"Id": "id",
"aadharId": "officialIds[0].value"
}
},
{
"operation": "modify-default-beta",
"spec": {
// Add type field to officialIds
"officialIds[0].type": "aadhar"
}
}
]
This Jolt spec will perform the following steps:
Shift Operation 1:
Extract the nested JSON from payload_json and move its contents to the top level.
Shift Operation 2:
Rename the fields to match the target JSON structure.
Modify Operation: Add the type field to the officialIds array.
Applying this Jolt spec to your source JSON will produce the desired target JSON. You can test this transformation using a Jolt transformation tool or library in your preferred programming language.
You can solve this easily using JSLT: