按布尔值过滤节点

Filter nodes by a boolean value

我必须通过 IsNew 参数(真或假)过滤 JSON JSON的部分内容如下:

{
"data": [
  {
    "type": "users",
    "attributes": {
      "first-name": "student21",
      "last-name": "student21",
      "username": "student21",
      "role": "student",
      "IsNew": true
    },
    "relationships": {
      "groups": {
        "data": [
          {
            "type": "groups",
            "id": "123f"
          }
        ]
      }
    }
  },
  {
    "type": "users",
    "attributes": {
      "first-name": "student23",
      "last-name": "student23",
      "email": "",
      "avatar-url": null,
      "username": "student23",
      "role": "student",
      "IsNew": false
    },
    "relationships": {
      "groups": {
        "data": [
          {
            "type": "groups",
            "id": "456"
          }
        ]
      }
    }
  }
  ]

}

我试过以下表达式:

$..data..[?(@.IsNew == true)].username,

$..data..[?(@.IsNew == 'true')].用户名,

$..data..[?(@.IsNew == "true")].用户名

所有这些表达式 return 没有任何结果。

我需要分别为 "IsNew" == true 和 "IsNew" == false 的学生提取用户名。

  1. 要为 "IsNew" == true 的学生提取用户名,请使用具有以下设置的 JSON 提取器:
    • JSON 路径表达式:$.data..attributes[?(@.IsNew =~ /.*true/i)].username
    • 匹配号-1[获取多个学生的所有匹配项]

  1. 要为 "IsNew" == false 的学生提取用户名,请使用具有以下设置的 JSON 提取器:
    • JSON 路径表达式:$.data..attributes[?(@.IsNew =~ /.*false/i)].username
    • 匹配号-1[获取多个学生的所有匹配项]

  1. 使用以下变量进一步处理:

    • ${FalseStudent_matchNr} 或 ${FalseStudent} 如果您在 JSON Extractor
    • 中使用了除 -1 以外的匹配号
    • ${TrueStudent_matchNr} 或 ${TrueStudent} 如果您在 JSON Extractor
    • 中使用了除 -1 以外的匹配号