我正在尝试删除具有null值的空字符串的""
表示。
例如JSON主体:
{
"eid": "string" ,
"iccid": "string" ,
"profileType": "",
"resultData":"" ,
"notificationPointId": 3 ,
"header": ""
}
目标JSON:
{
"eid": "string" ,
"iccid": "string" ,
"profileType": null,
"resultData":null ,
"notificationPointId": 3 ,
"header": null
}
您可以像这样使用jq
编译器:
jq ' .profileType = if .profileType == "" then null else .profileType end
| .resultData = if .resultData == "" then null else .resultData end
| .header = if .header == "" then null else .header end
'
empty_null.json
由于您必须将JSON作为字符串处理,因此在DP XSLT中使用标准regexp:replace
应该是可行的。。。来自您的样品,例如:
<!-- Add regexp ns to the XSLT declaration, e.g: -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions"
xmlns:regexp="http://exslt.org/regular-expressions"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="dp"
>
<xsl:variable name="nullJSON"
select="regexp:replace($str,'""','','')"/>
但是,如果您处理JSON,您应该真正将转换更改为GatewayScript!