I’m working on a JOLT transformation but haven’t been very successful so far. I have this input:
{
"primaryID": "DNI",
"DNI": 123,
"CUIL": 345
}
where the primaryID is dynamic, and I could also have different IDs. Instead of having DNI and CUIL, I could have many different labels. With that input, I’d need the following output:
{
"NationalIds" : [ {
"Type" : "CUIL",
"Number": 345
}, {
"Type" : "DNI",
"isPrimary" : "true",
"Number" : 123
} ]
}
I’ve been working on this JOLT transformation:
[
{
"operation": "shift",
"spec": {
"primaryID": {
"$": "@(0)"
},
"*": "&"
}
},
{
"operation": "shift",
"spec": {
"CUIL": "NationalIds.CUIL",
"DNI": "NationalIds.DNI"
}
},
{
"operation": "shift",
"spec": {
"NationalIds": {
"*": {
"@(2,Country)": "NationalIds[#2].Country",
"$": "NationalIds[#2].Type",
"@": "NationalIds[#2].Number"
}
}
}
},
{
"operation": "shift",
"spec": {
"NationalIds": {
"*": {
"Type": "NationalIds[&1].Type",
"Number": {
"*": {
"primaryID": {
"#true": "NationalIds[&4].isPrimary"
},
"*": {
"$": "NationalIds[&4].Number"
}
}
}
}
}
}
}
]
But the output that I get is:
{
"NationalIds" : [ {
"Type" : "CUIL"
}, {
"Type" : "DNI",
"isPrimary" : "true",
"Number" : "123"
} ]
}
Any ideas would be highly appreciated!
New contributor
Maite Reffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.