如果 属性 为空或缺失,则使用 jolt 变换从 Json 数组中删除 Json 个元素
Removing Json elements from the Json array if property is empty or missing using jolt transform
如果对象中的 属性 缺失或为空
,我将尝试删除 JSON 元素
{
"enterprise": "",
"Inactive_enterprise_id": null,
"emp_ID": "123456",
"Inactive_emp_id": "000821972",
"Username": "",
"A_ID": "fsgf1234jhgfs3",
}
这是我得到的:
"identifiers" : [ {
"type" : "enterprise"
}, {
"type" : "Inactive_enterprise_id"
}, {
"type" : "network"
}, {
"identifier" : "123456",
"type" : "emp_ID"
}, {
"identifier" : "000821972",
"type" : "Inactive_emp_id"
}, {
"identifier" : "fsgf1234jhgfs3",
"type" : "A_ID"
} ]
预期输出:
"identifiers" :
[
{
"identifier" : "123456",
"type" : "emp_ID"
}, {
"identifier" : "000821972",
"type" : "Inactive_emp_id"
}, {
"identifier" : "fsgf1234jhgfs3",
"type" : "A_ID"
} ]
我尝试了不同网站提供的不同 JsonSpecs,能够匹配预期的输出。也尝试使用两班制操作但没有成功,任何帮助或建议将不胜感激。
谢谢。
这个不能直接移位,下面link有解决方法,
https://github.com/bazaarvoice/jolt/issues/130
[
{
"operation": "default",
"spec": {
"*": ""
}
},
{
"operation": "shift",
"spec": {
"*": {
"": "TRASH",
"*": {
"@1": "&2"
}
}
}
},
{
"operation": "remove",
"spec": {
"TRASH": ""
}
}, {
"operation": "shift",
"spec": {
"*": {
"@": "identifiers.[#2].identifier",
"$": "identifiers.[#2].type"
}
}
}
]
如果对象中的 属性 缺失或为空
,我将尝试删除 JSON 元素{
"enterprise": "",
"Inactive_enterprise_id": null,
"emp_ID": "123456",
"Inactive_emp_id": "000821972",
"Username": "",
"A_ID": "fsgf1234jhgfs3",
}
这是我得到的:
"identifiers" : [ {
"type" : "enterprise"
}, {
"type" : "Inactive_enterprise_id"
}, {
"type" : "network"
}, {
"identifier" : "123456",
"type" : "emp_ID"
}, {
"identifier" : "000821972",
"type" : "Inactive_emp_id"
}, {
"identifier" : "fsgf1234jhgfs3",
"type" : "A_ID"
} ]
预期输出:
"identifiers" :
[
{
"identifier" : "123456",
"type" : "emp_ID"
}, {
"identifier" : "000821972",
"type" : "Inactive_emp_id"
}, {
"identifier" : "fsgf1234jhgfs3",
"type" : "A_ID"
} ]
我尝试了不同网站提供的不同 JsonSpecs,能够匹配预期的输出。也尝试使用两班制操作但没有成功,任何帮助或建议将不胜感激。
谢谢。
这个不能直接移位,下面link有解决方法,
https://github.com/bazaarvoice/jolt/issues/130
[
{
"operation": "default",
"spec": {
"*": ""
}
},
{
"operation": "shift",
"spec": {
"*": {
"": "TRASH",
"*": {
"@1": "&2"
}
}
}
},
{
"operation": "remove",
"spec": {
"TRASH": ""
}
}, {
"operation": "shift",
"spec": {
"*": {
"@": "identifiers.[#2].identifier",
"$": "identifiers.[#2].type"
}
}
}
]