Hi guys! I have some problem with joltTransformation.I have json like that:
{
"system": "TGG",
"income": "1000.0",
"costs": "700.0",
"id": "1",
"dateOfEvent": 1705446000000,
"name": "JAMES",
"surname": "SMITH",
"mail": "jsmith@gmail.com",
"dateOfBirth": 1705446000000,
"country": "US",
"city": "ORLANDO",
"eventId": "22",
"eventName": "EVENT",
"personalData": "true"
}
And I need output like this:
{
"system" : "TGG",
"income" : "1000.0",
"costs" : 700.0,
"id" : "1",
"dateOfEvent" : 1705446000000,
"person" : {
"name" : "JAMES",
"surname" : "SMITH",
"mail" : "jsmith@gmail.com",
"dateOfBirth" : 1705446000000,
"address" : {
"country" : "US",
"city" : "ORLANDO"
}
},
"eventData" : {
"personalData" : true,
"eventName" : "EVENT",
"eventId" : "22"
}
}
I have JoltSpec like this:
[
{
"operation": "shift",
"spec": {
"system": "system",
"income": {
"": {
"": "income"
},
"*": {
"$": "income"
}
},
"costs": {
"": {
"": "costs"
},
"*": {
"$": "costs"
}
},
"id": "id",
"dateOfEvent": {
"": {
"": "dateOfEvent"
},
"*": {
"$": "dateOfEvent"
}
},
"name": "person.name",
"surname": "person.surname",
"mail": "person.mail",
"dateOfBirth": {
"": {
"": "person.dateOfBirth"
},
"*": {
"$": "person.dateOfBirth"
}
},
"country": "person.address.country",
"city": "person.address.city"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"dateOfEvent": "=toLong(@(1,dateOfEvent))",
"costsArray": "=split('[,]',@(1,costs))",
"costsJoin": "=join('.',@(1,costsArray))",
"costs": "=toDouble(@(1,costsJoin))",
"incomeArray": "=split('[,]',@(1,income))",
"incomeJoin": "=join('.',@(1,incoemArray))",
"income": "=toDouble(@(1,incomeJoin))",
"eventData": {
"personalData": "=toBoolean(@(1,personalData))"
},
"person": {
"dateOfBirth": "=toLong(@(1,dateOfBirth))"
}
}
},
{
"operation": "default",
"spec": {
"income": null,
"costs": null,
"dateOfEvent": null,
"person": {
"dateOfBirth": null
},
"eventData": {
"eventName": "${eventName}",
"eventId": "${eventId}",
"personalData": "${personalData}"
}
}
},
{
"operation": "remove",
"spec": {
"costsArray": "",
"costsJoin": "",
"incomeArray": "",
"incomeJoin": ""
}
}
]
Everything is fine when I have data like dateOfBirth or income or costs. But when this data are null my json changes its forms and this data ends up at the and and look like this:
{
"system" : "TGG",
"costs" : 700.0,
"id" : "1",
"person" : {
"name" : "JAMES",
"surname" : "SMITH",
"mail" : "jsmith@gmail.com",
"address" : {
"country" : "US",
"city" : "ORLANDO"
},
"dateOfBirth" : null
},
"eventData" : {
"eventName" : "${eventName}",
"eventId" : "${eventId}",
"personalData" : "${personalData}"
},
"income" : null,
"dateOfEvent" : null
}
I need the json to always look the same, fields to be in the same order, regardless of whether they have values or are null-How can I improve this in my jolt spec?