Answered

Spaces in the JSON key

I'm testing some APIs and came across the issue with spaces in the json response. I'm using "Get_Rest_Value" method to get a value from specific key located within the JSON response provided below. If I use key "Locations.Targets.Preferred.State", i get proper value "Texas". My problem with keys which have spaces such as "Country Name". Any ideas how these keys should be constructed? I tried surround it with different kinds of brackets with no luck.

{
"Locations": [
{
"inputLat": 33.946,
"inputLon": -98.5,
"inputTargets": "STATES",
"inputBufferAnalysis": false,
"code": "GEN001",
"description": "Valid request proceeding with analysis.",
"Targets": [
{
"Target": "STATES",
"code": "SAR001",
"description": "The location is in a feature in the target layer. Analysis indicates that this is the most probable result.",
"Preferred": [
{
"State": "Texas",
"State FIPS Code": "48",
"Country Name": "United States",
"Country Abbreviation": "US",
"Senator 1 Name": "John Cornyn",
"Senator 1 Party Affiliation": "R",
"Senator 1 Phone Number": "202-224-2934",
"Senator 1 Website": "https://www.cornyn.senate.gov/",
"Senator 1 Office Address": "517 Hart Senate Office Building Washington DC 20510",
"Senator 2 Name": "Ted Cruz",
"Senator 2 Party Affiliation": "R",
"Senator 2 Phone Number": "202-224-5922",
"Senator 2 Website": "https://www.cruz.senate.gov",
"Senator 2 Office Address": "404 Russell Senate Office Building Washington DC 20510"
}
],
"Possible": []
}
]
}
]
}

 

0
3 comments
Avatar
Joseph Hamdan

Hi Vitaly,

Could you please try the below in the Keys/XPaths:

Locations[0].Targets[0].Preferred[0].['Country Name']

Regards,

Subject7 Team

0
Comment actions Permalink
Avatar
Vitaly Melnik

Awesome. Works as expected. Thank you . You saved me a lot of time ;)

Just a quick question. So, is it bad practice to create keys in "Get_Rest_Value" or "Verify_Rest_Value" methods without using indexes (e.g. Locations.Targets.Preferred.Something)? Or it should work both ways but we should use indexes in cases when we have node with spaces like in my case?

0
Comment actions Permalink
Avatar
Joseph Hamdan

Hi Vitaly,

You are most welcome. When the key has space we have to surround this key with [' and ']. We use indexes when we need to get specific element from the array, otherwise it will catch the first element from the array. Based on that, Locations.Targets.Preferred.['Country Name'] should also work and select the first elements but we have a bug for this case. 

Regards,

Subject7 Team

0
Comment actions Permalink

Please sign in to leave a comment.