I have a json input that has an array in it. This array could have zero, one or many elements:
{
"education": [
{
"institutionName": "Testing Institution",
"startDate": "Mar-2010",
"endDate": "Mar-2015",
"registrarPhone": ""
},
{
"institutionName": "",
"startDate": "Mar-2010",
"endDate": "Mar-2015",
"registrarPhone": "(888) 345-5849"
},
{
"institutionName": "",
"startDate": "Mar-2010",
"endDate": "Mar-2015",
"registrarPhone": ""
}
]
}
Sometimes, the keys named "institutionName" and "registrarPhone" could come with an empty value. But these fields are mandatory for the API to which I am sending them. So I need to add some dummy values to them, only when they are empty.
Since these are fields with different formats, I cannot put together a generic transformation to fill all empty fields with the same value. That's why I need the "institutionName"
field to be filled with "N/A"
and the "registerPhone"
field to be filled with "(111) 111-1111"
.
So the output should be:
{
"education": [
{
"institutionName": "Testing Institution",
"startDate": "Mar-2010",
"endDate": "Mar-2015",
"registrarPhone": "(111) 111-1111"
},
{
"institutionName": "N/A",
"startDate": "Mar-2010",
"endDate": "Mar-2015",
"registrarPhone": "(888) 345-5849"
},
{
"institutionName": "N/A",
"startDate": "Mar-2010",
"endDate": "Mar-2015",
"registrarPhone": "(111) 111-1111"
}
]
}
I was trying with several JOLTs that I found, but they only work for populating an array that is completely empty, and not for populating particular elements within an array.
Is there any way to carry this out?
Thank you very much in advance!
You can
""
by matching
""
vs. null
within a shift transformation spec~
operator within a modify transformation spec in order to set their value to fixed ones as they're currently do not existsuch as :
[
{
"operation": "shift",
"spec": {
"education": {
"*": {
"institutionName|registrarPhone": {
"": null,
"*": {
"@1": "&4[&3].&2"
}
},
"*": {
"*": {
"@1": "&4[&3].&2"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"education": {
"*": {
"~institutionName": "N/A",
"~registrarPhone": "(111) 111-1111"
}
}
}
},
{ // this transformation spec stands only for ordering of the
// attributes due to the original manner
"operation": "shift",
"spec": {
"education": {
"*": {
"institutionName|startDate|endDate|registrarPhone": "&2[&1].&"
}
}
}
}
]