繁体   English   中英

检查json属性是否为null

[英]Check if json property is null

我有以下输入

{
  "headers": {
   ...
},
  "body": {
    "RequestInfo": {
     ...
    ,
     "Identificator": null
        }
}

<filter regex="false" source="boolean($ctx:Identificator)"> -check if exist(when it's null it still viewed as existing.)

我正在创建用于检查Identificator值的服务。

但是在这种情况下,它为空。 有人可以在xpath中给我一个例子,说明该检查为null而不是有效值时应如何进行检查?

编辑:有人可以用JavaScript向我展示,因为这种方法行不通,我将如何获得标识符的价值?

EDIT2:JS可以工作,但事实证明,在WSO2中,当我们获得标识符时,将null视为字符串,因此ctx:Identificator ='null'也可以工作。

在javascript中,您可以这样做:

    let myJsonString = "{
       "headers": {
            ...
        },
       "body": {
           "RequestInfo": {
                ...,
               "Identificator": null
            }
        }
    }"
    const parsedJsonValue = JSON.parse(myJsonString);
    const {body} = parsedJsonValue;
    if(body && body.RequestInfo) {
        const {Identificator} = body.RequestInfo;
        if(Identificator === null || Identificator === undefined) {
            // Identificator is null
        }
    }

希望这就是您要寻找的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM