AnsweredAssumed Answered

Python: parse/extract json returned from locator service?

Question asked by ascullyCOT on Mar 21, 2019
Latest reply on Mar 21, 2019 by fallingdog

In a python script to be published as a GP service, I'm making a call to a Locator Service, getting results back - plan is to use the X & Y values from the locator return as input variables for some intersects etc. as part of the overall tool.  

 

The call/return from the locator is working, now I'm investigating the python json library to figure out how the extract just X & Y values into variables.  

My question is about whether/how you can use the json library to parse through the json and return the 2 attributes (the X and Y in my case) so they can be plugged into python variables..  

 

Results example:

 

{u'candidates': [{u'attributes': {u'Y': 446768.471952, u'X': 992202.058741}, u'score': 100, u'location': {u'y': 446768.47195232206, u'x': 992202.0587409921}, u'address': u'201 N STONE AV, TUCSON'}], u'spatialReference': {u'wkid': 2868, u'latestWkid': 2868}}

 

Alternately, after simply converting the Results to a string:

 

{
"spatialReference": {
"wkid": 2868,
"latestWkid": 2868
},
"candidates": [
{
"address": "201 N STONE AV, TUCSON",
"location": {
"x": 992202.0587409921,
"y": 446768.47195232206
},
"score": 100,
"attributes": {
"X": 992202.05874100002,
"Y": 446768.47195199999
}
}
]
}

 

 

Anyone been through this before?

 

Thanks - 

Allen

Outcomes