2021年1月29日星期五

Is it possible to do nested search in jsonpath-ng?

Source "mapping.json":

{    "result": {      "src_color": "test_rule_2"    },    "rules": {      "color_degree": {        "test_rule_1": {          "color": 1        },        "test_rule_2": {          "color": 2        }      }    }  }  

So it works perfectly:

with open("mapping.json", 'r') as json_file:      mapping = json.load(json_file)    expression = parse('$.rules.color_degree.test_rule_2.color')  match = expression.find(mapping)    if match:      pprint(match[0].value)  

but in the path "test_rule_2" I need to replace with the value from result->src_color

How to properly describe something like this:

expression = parse('$.rules.color_degree.($.result.src_color.value).color')  
https://stackoverflow.com/questions/65952517/is-it-possible-to-do-nested-search-in-jsonpath-ng January 29, 2021 at 06:14PM

没有评论:

发表评论