问题
If I have a json file with fields having special chars (in my case dots) how can I access the field value in Karate?
For example having a json file called example.json
{
"field1" : {
"field2" : "value2",
"field.3" : "value3"
}
}
if I want to get the value of "field.3" field how can do?
Scenario: read a json file
* def myJson = read("example.json")
* match myJson.field1.field2 == "value2"
* match myJson.field1.field.3 == "value3" # this fails
* match myJson.field1."field.3" == "value3" # this fails
* match myJson.field1.'field.3' == "value3" # this fails
* match myJson.field1.'field\.3' == "value3" # this fails
回答1:
Use square-brackets:
* myJson.field1['field.3']
来源:https://stackoverflow.com/questions/62404067/access-a-json-field-value-if-the-json-field-has-special-chars-as-dots