用于过滤名称不同的对象的集合的JSONPath语法

问题描述 投票:1回答:1

我有一个JSON对象

{
  "0_documentation": {
    "accountId": "The 12 digit AWS Account ID for the account",
    "alias": "Friendly name used to refer to this account (think name input in ssh-with-role)",
    "key": "This is the identifier you use for the account config, format: $domain.$realm.$service.$relativeId",
    "region": "The primary region where resources in this account are stored. Must be a valid AWS region",
    "region_partition": "This is ARN region partition (https://tiny.amazon.com/a51f4mku), this is usually a boundary of admin tools etc",
    "stage": "The deployment stage this account supports - alpha, beta, gamma, prod",
    "type": "The type of service supported by this account - service (single service stack - used in alphas), general (service account), canary, console"
  },
  "accounts": {
    "alpha.us-east-1.cambridgeuseraccount": {
      "accountId": "84624",
      "alias": "alpha",
      "region": "us-east-1",
      "region_partition": "aws",
      "stage": "alpha",
      "type": "service"
    },
    "beta.us-east-1.cambridgeuseraccount": {
      "accountId": "85236",
      "alias": "beta",
      "region": "us-east-1",
      "region_partition": "aws",
      "stage": "beta",
      "type": "service"
    },
    "prod.us-east-1.cambridgeuseraccount" : {
        "accountId": "85536",
      "alias": "beta",
      "region": "us-east-1",
      "region_partition": "aws",
      "stage": "prod",
      "type": "service"
      },
    "prod.eu-west-1.cambridgeuseraccount" : {
       "accountId": "128790",
      "alias": "beta",
      "region": "us-east-1",
      "region_partition": "aws",
      "stage": "prod",
      "type": "service"
     }
  }
}

我想提取属性帐户以“ prod”开头的所有帐户ID。

例如,我要使用accountIdsprod.us-east-1.cambridgeuseraccounttand prod.eu-west-1.cambridgeuseraccount

我想要预期的输出[128790 , 85536]作为上述JSON的输出

[我想要一个JSONPath查询,我已经尝试过

$.[?(@.accounts =~ /prod.*?/i)]

但是我没有得到任何结果

我正在关注此站点https://github.com/json-path/JsonPath作为参考

我有一个JSON对象{“ 0_documentation”:{“ accountId”:“该账户的12位AWS账户ID”,“ alias”:“用于引用此账户的友好名称(请以ssh-with输入名称) -...

json jsonpath rest-assured-jsonpath json-path-expression
1个回答
0
投票

我认为$.[?(@.accounts =~ /prod.*?/i)]无效。在“放心”中,“ JSON路径”语法使用Groovy's GPath

表示法,并且不要与Jayway's JsonPath
© www.soinside.com 2019 - 2024. All rights reserved.