4

I'm trying to convert some open-source data in JSON format to a shapefile for use in ArcGIS Desktop. I'm attempting to do this in ArcPy with ArcMap 10.7. The data I'm trying to access is here, in JSON format:

data from data.SF.gov

And my script:

#access the JSON from web link
bikeLanesRaw = 'https://data.sfgov.org/resource/ygmz-vaxd.json'
bikeLanesRawResponse = urllib2.urlopen(bikeLanesRaw)
bikeLanesRaw_JSON = bikeLanesRawResponse.read()
#Write each response to JSON
foo = open(bikeFacilitiesFolder + "\\" + "bikeLanes_SF.json", "wb")
foo.write(bikeLanesRaw_JSON);
foo.close()



#Convert JSON to shapefile - THIS FAILS
arcpy.JSONToFeatures_conversion(bikeFacilitiesFolder + "\\" + "bikeLanes_SF.json", bikeFacilitiesFolder + "\\" + "bikeLanes_SF.shp")

Everything works as expected until the final line, where I try and convert the JSON to features. It gives me the error:

 ExecuteError: ERROR 001558: Error parsing json file 'Bike Facilities Data\bikeLanes_SF.json'. 
Failed to execute (JSONToFeatures).

I've read more of ESRI documentation, and they say:

Review the JSON structure in the input file. The JSON must have at least the geometryType, spatialReference, fields, and features (with geometry and attributes) property.

What do I do if the JSON does not have this information to begin with?

1
  • 1
    Rather than provide only a link to a (presumably large) JSON file when potential answerers may be like me and prefer not to follow links, I think you should cut that JSON file down to a tiny sample that can be posted here as text, but still be used to show the error.
    – PolyGeo
    Commented Aug 7, 2019 at 22:07

1 Answer 1

4

The JSON to Features tool won't work for your case.

The tool wants either esri JSON or geoJSON. The JSON from that link is neither of those, it's straight up regular JSON. You'll need to find another parser to turn JSON into a shape/fgdb/geo-something.

You could research using cursors and building your own featureclass by parsing the JSON manually. There should be a lot of starter code on GIS.SE and the internet at large.

4
  • From what it sounds like, it should work with a GeoJSON. I'm able to find a Geojson of the data: data.sfgov.org/resource/ygmz-vaxd.geojson , though it's still giving me the same error when I pass this into JSON to Features tool? Commented Aug 7, 2019 at 18:30
  • 2
    Which product are you using? The ability to convert from GeoJSON was introduced at Pro 2.2 and appears to have never been back ported to ArcMap.
    – KHibma
    Commented Aug 7, 2019 at 19:02
  • I'm using ArcMap 10.7 . What about using arcPy's "AsShape"? This supposedly converts geojson to ESRI JSON, though I haven't been able to get it to work. Commented Aug 7, 2019 at 19:29
  • 1
    You might be able to use that. I'd try that. If you can't get it to work, that'd be a new question here.
    – KHibma
    Commented Aug 8, 2019 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.