I have been trying to modify a Json using Jolt and no matter what operators I try, I am not able to solve the problem. I'm working on v0.1.1 and using Jolt Transform Demo.
Considering that I should priorize reservation.date, use reservation.reservationList.date in case reservation.date is not provided and in case none of them are provided I should not show any date.
Input:
´{
"reservation": {
"date": "2024-03-01",
"reservationList": [
"language": "en",
"date": "2024-03-02"
]
}
Spected output:
´{
"reservation": {
"date": "2024-03-01",
"languaje": "en"
}
Thank you so much in advance if you could enlightme about it.
Hi you can use this spec to get desired output.
[
{
"operation": "shift",
"spec": {
"reservation": {
"reservationList": {
"*": {
"@(2,date)": "reservation.date",
"date": "reservation.date",
"language": "reservation.language"
}
}
}
}
},
{
"operation": "cardinality",
"spec": {
"reservation": {
"date": "ONE"
}
}
}
]
Explanation :
In second spec cardinality date : "ONE" means to extract the first value as a object into date field.
Here the priority will take place reservation.date is mapped first in previous spec so it will be 1st element of array, if reservation.date is not coming then reservation.reservationList.date will come and in case none of them are provided date wont be present.