Is there any alternative head
to transform and get first non empty or non null value from JSON array. similar to head(/part/subline/sublineGrouop/sublineGroupTP/detailsGP/dtlLine/details/code)
should return US
{
"part": {
"subline": {
"sublineGroup": {
"property1": "test",
"proerty2": "tes2",
"sublineGroupTP": {
"detailsGP": [
{
"dtlLine": {
"details": {
"code": null
}
}
},
{
"dtlLine": {
"details": {
"code": ""
}
}
},
{
"dtlLine": {
"details": {
"code": "US"
}
}
},
{
"dtlLine": {
"details": {
"code": "UK"
}
}
}
]
}
}
}
}
}
Expected Output JSON
{
"countryCode": "US"
}
2
Answers
You can use the following shift transformation.
An option is to write the whole path(s) preceded by @ sign, except for the parts with arrays, in which you might use a conditional in order to get an array with non-null and non-blank components, then pick the first components of the array by the function such as