Is it possible to add features from a JSON file to an existing feature class?

1060
3
Jump to solution
10-28-2021 02:30 PM
ScotWallace
New Contributor II

I am trying to use JSONToFeatures to add features from a JSON file to an existing empty feature class using arcpy and I get the following error:

ERROR 000206: Cannot create FeatureClass '<featureClass'. The workspace is not connected.

out_path = r"C:\\TMP"
gdb_name = "test.gdb"
gdb_full_path = os.path.join(out_path,gdb_name)

arcpy.env.workspace = gdb_full_path
try:
    jsonFile = os.path.join(out_path,'Account.json')
    featureClass = os.path.join(gdb_full_path,'Account')
    arcpy.JSONToFeatures_conversion(jsonFile, featureClass)
except RuntimeError as err:
    print(err)

If I delete the target Account feature class then run this code, it works and Account is written to a new feature class.

Unfortunately, I am having to add these features to an existing feature class as certain input string fields are longer than the ArcGIS default 1024 chars and so I need to have these field widths pre-configured to avoid other errors.

Python 2.7
ArcDesktop 10.8

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

Works for me. With a very large string field in my GeoJSON, I get a default width of 8000 in the output FGDB featureclass.

 With an Esri JSON file, the field length is explicit, so you can set it to whatever length you need before running JSONToFeatures.

"fields":[{"name":"some_attribute","type":"esriFieldTypeString","alias":"some_attribute","length":15000}]

 

 

View solution in original post

0 Kudos
3 Replies
Luke_Pinner
MVP Regular Contributor
arcpy.JSONToFeatures_conversion(jsonFile, Temp_or_InMemory_featureClass)

arcpy.Append_management(
    Temp_or_InMemory_featureClass, output_featureClass,
    schema_type="NO_TEST",  
    field_mapping="your field mapping")

Tip - try without schema_type and field_mapping. If it works then no need to specify those optional parameters, otherwise run the Append manually and copy the python snippet for it from the results window to get the appropriate field mapping string. 

0 Kudos
ScotWallace
New Contributor II

I'm running into the same problem with that as I'm not able to pre-configure the field widths for the temporary feature class so I still get the error from JSONToFeatures.

0 Kudos
Luke_Pinner
MVP Regular Contributor

Works for me. With a very large string field in my GeoJSON, I get a default width of 8000 in the output FGDB featureclass.

 With an Esri JSON file, the field length is explicit, so you can set it to whatever length you need before running JSONToFeatures.

"fields":[{"name":"some_attribute","type":"esriFieldTypeString","alias":"some_attribute","length":15000}]

 

 

0 Kudos