I am new to JOLT and I don’t know much about it, and I need the JOLT spec to convert my below JSON to CSV file:
{
"bigRecords": [
{
"Records": {
"Name": "R1",
"Id": "1P02XV425KCASEZGQLB8LPQMF4ZXCUBCTA01",
"Type": "New",
"Area": "Eng",
"createdAt": "11-10-2022 06:10:00",
"deletedDate": "11-10-2022 06:20:00",
"deleted": true,
"deletedBy": "userId",
"createdBy": "userId"
},
"ancestors": [
{
"Name": "P1",
"Type": "DELETE",
"sta": "",
"some": "",
"Id": "1"
}
]
},
{
"Records": {
"Name": "R2",
"Id": "1P02XV425KCASEZGQLB8LPQMF4ZXCUBCTA01",
"Type": "DRAFT",
"Area": "Eng",
"createdAt": "11-10-2022 06:10:00",
"deletedDate": "11-10-2022 06:20:00",
"deleted": true,
"deletedBy": "userId",
"createdBy": "userId"
},
"dependentRecords": [
{
"Name": "P3",
"Type": "DELETE",
"sta": "1P0",
"some": "1P02",
"Id": "1P0"
}
]
}
]
}
Please help me in convert the complex json to CSV using the JOlT library, or any other way I can do achieve this, in spring boot?
3
Answers
You have JsonFlattener which is easy to use.
https://github.com/wnameless/json-flattener
// {a.b=1, a.c=null, a.d[0]=false, a.d[1]=true, e=f, g=2.3}
Library Josson has
flatten()
function. It also has functionunflatten()
to reverse the operation.https://github.com/octomix/josson
Deserialization
Style 1
Output
Style 2
Output
Through using
Jolt
;you can separate the levels by respective deepness of the leaves, and tile underscore separated ampersands which are node representatives in order to flatten the whole JSON such as
which yields