I am attempting to write a Jolt transformation specification to convert nested JSON to flat JSON with rows. The goal is to create a single spec that can handle both Input Data 1 and Input Data 2.
Input Data 1
{
"Id": "123",
"Name": "tets",
"records": [
{
"aaa": "123",
"test": [
{
"zzz": 987,
"yyy": 123
},
{
"zzz": 345,
"yyy": 678
}
]
}
]
}
Input Data 2
[
{
"Id": "123",
"Name": "tets",
"records": [
{
"aaa": "123",
"test": [
{
"zzz": 987,
"yyy": 123
},
{
"zzz": 345,
"yyy": 678
}
]
}
]
},
{
"Id": "1234",
"Name": "tets2",
"records": [
{
"aaa": "123",
"test": [
{
"zzz": 987,
"yyy": 123
},
{
"zzz": 345,
"yyy": 678
}
]
},
{
"aaa": "12345",
"test": [
{
"zzz": 456,
"yyy": 567
}
]
}
]
}
]
I want the output for input 1
[
{
"Id": "123",
"Name": "tets",
"records.aaa": "123",
"records.test.zzz": 987,
"records.test.yyy": 123
},
{
"Id": "123",
"Name": "tets",
"records.aaa": "123",
"records.test.zzz": 345,
"records.test.yyy": 678
}
]
And for input 2, the output should be in the below format
[
{
"Id": "123",
"Name": "tets",
"records.aaa": "123",
"records.test.zzz": 987,
"records.test.yyy": 123
},
{
"Id": "123",
"Name": "tets",
"records.aaa": "123",
"records.test.zzz": 345,
"records.test.yyy": 678
},
{
"Id": "1234",
"Name": "tets2",
"records.aaa": "123",
"records.test.zzz": 987,
"records.test.yyy": 123
},
{
"Id": "1234",
"Name": "tets2",
"records.aaa": "123",
"records.test.zzz": 345,
"records.test.yyy": 678
},
{
"Id": "1234",
"Name": "tets2",
"records.aaa": "12345",
"records.test.zzz": 456,
"records.test.yyy": 567
}
]
2
Answers
You can use the following spec
You can use this spec:
NOTE: If you have more nested values, you should sure about how many they are, then JOLT can help you achieve your desired output. Otherwise, you can find another way with other tools or libraries.