I am new to JOLT Transformation and I found it really useful in JSON Transformations. But when i come across with a nested and complex JSON I get confused.
The following JSON is a nested and complex JsonArray that I need to transform it into a completely Flat JsonArray.
JSON Input:
[
{
"Code": -1,
"Name": "All",
"PublisherTypes": [
{
"Code": 2,
"Name": "General",
"LetterTypes": []
},
{
"Code": 3,
"Name": "Financials",
"LetterTypes": []
}
]
},
{
"Code": 1,
"Name": "Information",
"PublisherTypes": [
{
"Code": 2,
"Name": "General",
"LetterTypes": [
{
"Id": 10,
"Name": "Long Term Info",
"Code": ""
},
{
"Id": 20,
"Name": "Short Term Info",
"Code": ""
}
]
},
{
"Code": 3,
"Name": "Financials",
"LetterTypes": [
{
"Id": 101,
"Name": "Total Income",
"Code": ""
},
{
"Id": 202,
"Name": "Total Taxes",
"Code": ""
}
]
}
]
},
{
"Code": 2,
"Name": "Reporting",
"PublisherTypes": [
{
"Code": 2,
"Name": "General",
"LetterTypes": [
{
"Id": 8,
"Name": "Monthly Reoprt",
"Code": ""
},
{
"Id": 58,
"Name": "Status Report",
"Code": ""
}
]
},
{
"Code": 3,
"Name": "Financials",
"LetterTypes": [
{
"Id": 170,
"Name": "Manager Level",
"Code": ""
},
{
"Id": 156,
"Name": "Expert Level",
"Code": ""
}
]
}
]
}
]
As you see, we have the Object "LetterTypes":[] that is empty but in the other Json Objects "LetterTypes" has its own Objects and is not empty.
And the following JSON is my Expected Output.
Expected Output:
[
{
"Code": -1,
"Name": "All",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": "",
"LetterName": "",
"LetterCode": ""
},
{
"Code": -1,
"Name": "All",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": "",
"LetterName": "",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 10,
"LetterName": "Long Term Info",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 20,
"LetterName": "Short Term Info",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 101,
"LetterName": "Total Income",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 202,
"LetterName": "Total Taxes",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 8,
"LetterName": "Monthly Reoprt",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 58,
"LetterName": "Status Reoprt",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 170,
"LetterName": "Manager Level",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 156,
"LetterName": "Expert Level",
"LetterCode": ""
}
]
What I need is a JOLT Spec to generate above Output for me So That when "LetterTypes" is empty it is displayed in the output with Empty String("") values. So, can anyone provide a JOLT Spec for this problem?