使用 Jolt 从 JSON 输出中删除空值
Remove null values from JSON output using Jolt
您能否建议我一种从 json 输出中删除空值的方法,如下所述:
输入
{
"userId": "1",
"age": "20",
"desc1": "value desc1",
"desc2": "value desc2",
"desc3": "value desc3",
"desc4": "value desc4",
"desc5": "value desc5",
"desc6": "value desc6",
"desc7": "value desc7"
}
规格
[
{
"operation": "shift",
"spec": {
"desc4": "test4",
"desc5": "test5",
"desc6": "test6",
"desc1|desc2|desc3": {
"$": "additionalInformationList[#2].typeCode",
"@": "additionalInformationList[#2].value"
}
}
}
]
输出
{
"test4": "value desc4",
"test5": "value desc5",
"test6": "value desc6",
"additionalInformationList": [null,null,null,
{
"typeCode": "desc1",
"value": "value desc1"
},
{
"typeCode": "desc2",
"value": "value desc2"
},
{
"typeCode": "desc3",
"value": "value desc3"
}
]
}
关于如何删除空值的任何建议?
确实够用
[
{
"operation": "shift",
"spec": {
"desc*": "&",
"desc1|desc2|desc3": {
"$": "additionalInformationList[#2].typeCode",
"@": "additionalInformationList[#2].value"
}
}
},
{
"operation": "remove",
"spec": {
"desc7": ""
}
}
]
如果您不使用 test 重命名 desc 属性以获得
{
"additionalInformationList" : [ {
"typeCode" : "desc1",
"value" : "value desc1"
}, {
"typeCode" : "desc2",
"value" : "value desc2"
}, {
"typeCode" : "desc3",
"value" : "value desc3"
} ],
"desc4" : "value desc4",
"desc5" : "value desc5",
"desc6" : "value desc6"
}
对于目前的情况,可以使用
[
{
"operation": "shift",
"spec": {
"desc*": "test&",
"desc1|desc2|desc3": {
"$": "additionalInformationList[#2].typeCode",
"@": "additionalInformationList[#2].value"
}
}
},
{
"operation": "shift",
"spec": {
"test*": {
"$": "@(0)"
},
"*": "&"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*desc*": "=split('desc',@(1,&))"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*desc*": "=join('',@(1,&))"
}
},
{
"operation": "shift",
"spec": {
"*desc*": {
"$": "@(0)"
},
"*": "&"
}
},
{
"operation": "remove",
"spec": {
"test7": ""
}
}
]
或更短的大小写,分别写入 desc4、desc5 和 desc6[=33 的键值对=] 属性可能是
[
{
"operation": "shift",
"spec": {
"desc4": "test4",
"desc5": "test5",
"desc6": "test6",
"desc*": {
"$": "&.code",
"@": "&.value"
}
}
},
{
"operation": "remove",
"spec": {
"desc7": ""
}
},
{
"operation": "shift",
"spec": {
"test*": "&",
"*": "additionalInformation[]"
}
}
]
您能否建议我一种从 json 输出中删除空值的方法,如下所述:
输入
{
"userId": "1",
"age": "20",
"desc1": "value desc1",
"desc2": "value desc2",
"desc3": "value desc3",
"desc4": "value desc4",
"desc5": "value desc5",
"desc6": "value desc6",
"desc7": "value desc7"
}
规格
[
{
"operation": "shift",
"spec": {
"desc4": "test4",
"desc5": "test5",
"desc6": "test6",
"desc1|desc2|desc3": {
"$": "additionalInformationList[#2].typeCode",
"@": "additionalInformationList[#2].value"
}
}
}
]
输出
{
"test4": "value desc4",
"test5": "value desc5",
"test6": "value desc6",
"additionalInformationList": [null,null,null,
{
"typeCode": "desc1",
"value": "value desc1"
},
{
"typeCode": "desc2",
"value": "value desc2"
},
{
"typeCode": "desc3",
"value": "value desc3"
}
]
}
关于如何删除空值的任何建议?
确实够用
[
{
"operation": "shift",
"spec": {
"desc*": "&",
"desc1|desc2|desc3": {
"$": "additionalInformationList[#2].typeCode",
"@": "additionalInformationList[#2].value"
}
}
},
{
"operation": "remove",
"spec": {
"desc7": ""
}
}
]
如果您不使用 test 重命名 desc 属性以获得
{
"additionalInformationList" : [ {
"typeCode" : "desc1",
"value" : "value desc1"
}, {
"typeCode" : "desc2",
"value" : "value desc2"
}, {
"typeCode" : "desc3",
"value" : "value desc3"
} ],
"desc4" : "value desc4",
"desc5" : "value desc5",
"desc6" : "value desc6"
}
对于目前的情况,可以使用
[
{
"operation": "shift",
"spec": {
"desc*": "test&",
"desc1|desc2|desc3": {
"$": "additionalInformationList[#2].typeCode",
"@": "additionalInformationList[#2].value"
}
}
},
{
"operation": "shift",
"spec": {
"test*": {
"$": "@(0)"
},
"*": "&"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*desc*": "=split('desc',@(1,&))"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*desc*": "=join('',@(1,&))"
}
},
{
"operation": "shift",
"spec": {
"*desc*": {
"$": "@(0)"
},
"*": "&"
}
},
{
"operation": "remove",
"spec": {
"test7": ""
}
}
]
或更短的大小写,分别写入 desc4、desc5 和 desc6[=33 的键值对=] 属性可能是
[
{
"operation": "shift",
"spec": {
"desc4": "test4",
"desc5": "test5",
"desc6": "test6",
"desc*": {
"$": "&.code",
"@": "&.value"
}
}
},
{
"operation": "remove",
"spec": {
"desc7": ""
}
},
{
"operation": "shift",
"spec": {
"test*": "&",
"*": "additionalInformation[]"
}
}
]