是否有任何替代方法
head
来转换并从 JSON 数组获取第一个非空或非空值。类似于head(/part/subline/sublineGrouop/sublineGroupTP/detailsGP/dtlLine/details/code)
应该返回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"
}
}
}
]
}
}
}
}
}
{
"countryCode": "US"
}
您可以使用以下shift转换。
[
{
"operation": "shift",
"spec": {
"part": {
"subline": {
"sublineGroup": {
"sublineGroupTP": {
"detailsGP": {
"*": {
"dtlLine": {
"details": {
"code": {
"": "", //Skip null and empty values.
"*": {
"@(2,&1)": "countryCode" //Group non-null values
}
}
}
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"countryCode": {
"0": "&1" // 1st item in the array.
}
}
}
]