I am writing a small script taking Excel to a point layer in ArcGIS Pro. My question involves a small expression parsing the x and y coordinates from a single long string. The string is formatted as follows:
{"AddressCandidates":[{"location":{"spatialReference":{"wkid":4326},"x":-88.32831272050885,"y":42.00719348709284}}],"SelectedCandidate":{"location":{"spatialReference":{"wkid":4326},"x":-88.32831272050885,"y":42.00719348709284}},"LastGeocodedAddress":null
I am using the calculate fields (multiple). I cannot use string length because it varies. I think I can identify the "x": and "y": using message.find
I am a student trying to learn, any help would be appreciated.
Your data is in a format called JSON which can be unpacked easily.
import arcpy
import json
your_string = 'your JSON coordinate string'
data = json.loads(your_string)
x = data["AddressCandidates"][0]["location"]["x"]
y = data["AddressCandidates"][0]["location"]["y"]