Forum Discussion
I know I can do that manually. That is great if you never want the field and know which portions you don’t want. Neither is the case for me.
If I have:
"Address": [{
"value": {
"AddressType": {
"value": "Mailing"
},
"AddressLine1": {
"value": "3740 Turtle ST"
},
"City": {
"value": "DALLAS"
},
"StateProvince": {
"value": "TX"
},
"Zip": {
"value": "75215"
},
"Country": {
"value": "US"
}
}
}, {
"value": {
"AddressType": {},
"AddressLine1": {},
"City": {},
"StateProvince": {},
"Zip": {},
"Country": {}
}
}]
I want it to be changed to:
“Address”: [{
“value”: {
“AddressType”: {
“value”: “Mailing”
},
“AddressLine1”: {
“value”: “3740 Turtle ST”
},
“City”: {
“value”: “DALLAS”
},
“StateProvince”: {
“value”: “TX”
},
“Zip”: {
“value”: “75215”
},
“Country”: {
“value”: “US”
}
}
}
}]
Of course, there are other parts that may or may not be null. I want any null part to be ignored.
Do you have any ideas how to use such functionality for a general case such as this? The models may change, and there are several.
Steve
For your specific Address example, I found this expression to work:
$Address.filter((v1,k1)=>!v1.value.filter((v2,k2)=>!v2.isEmpty()).isEmpty())
Logically, it also works like this:
$Address.filter((v1,k1)=>v1.value.filter((v2,k2)=>v2.isEmpty()).isEmpty())
No recursion though, so @tstack’s solution is definitely a better approach if that’s required.