So I think that there might be several problems here. JSONToFeatures does not seem to want to output to the "memory" space but it will write to "in_memory"; however, after writing, it does not show up as a feature class using ListFeatureClasses-- --even though it appears as such using describe.
import arcpy
#rename to your path, and replace .txt with .json
json_input = r"WHATEVERPATH\test.json"
arcpy.env.overwriteOutput = True
try:
arcpy.env.workspace = "memory"
arcpy.JSONToFeatures_conversion(json_input, "json_output")
except Exception as e:
print(f"There's this 000206 Error when running the {arcpy.env.workspace} workspace:\n\n{e}")
arcpy.env.workspace = "in_memory"
arcpy.JSONToFeatures_conversion(json_input, "json_output")
print(f"But it seems to work fine running the {arcpy.env.workspace} workspace")
print(f"\n\tThis item exists: {arcpy.Exists('json_output')}")
json_in_memory = arcpy.Describe("json_output")
print(f"\tThis item is a: {json_in_memory.dataType}")
print(f"\tThis item is located at: {json_in_memory.catalogPath}")
list_fc = arcpy.ListFeatureClasses()
print(f"\n\tBut, when we check our current workspace {arcpy.env.workspace}, it returns no feature classes {list_fc}")
Using the Python Kernel from ArcGIS Pro 2.7.1
if arcpy.Exists("json_output") # ???
# do you mean
if arcpy.Exists(json_input)
No, that was a convenience function that I threw in there to assist in running multiple times; I guess I could have set overwrite = True to avoid that confusion.
well this has nothing to describe
json_in_memory = arcpy.Describe("json_output")
I would suggest dumping the try except block and do something about the non-existent variable (which is just a string)
I'm treating that as a path to where that memory feature class is supposed to reside, with the env set these two are equivalent.
json_in_memory = arcpy.Describe("json_output")
json_in_memory = arcpy.Describe("in_memory\json_output")
I think the bigger issue here is that JSONToFeatures_conversion gets wonky when it is not writing to a "physical" space like a shapefile, GDB, or similar.
For everyone playing along at home; this issue is half-fixed (at ArcGIS Pro 3.1.0). You can now use JSONToFeatures_conversion, but you still cannot ListFeatureClasses() within the memory workspace.
I'll update the sample to some accessible data:
https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_lakes.geojson
import arcpy
# you can grab this data from here https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_lakes.geojson
json_input = r"YOUR_PATH_HERE\ne_110m_lakes.geojson"
arcpy.env.overwriteOutput = True
try:
arcpy.env.workspace = "memory"
arcpy.JSONToFeatures_conversion(json_input, "json_output")
except Exception as e:
print(f"There's this 000206 Error when running the {arcpy.env.workspace} workspace:\n\n{e}")
arcpy.env.workspace = "in_memory"
arcpy.JSONToFeatures_conversion(json_input, "json_output")
print(f"But it seems to work fine running the {arcpy.env.workspace} workspace")
print(f"\n\tThis item exists: {arcpy.Exists('json_output')}")
json_in_memory = arcpy.Describe("json_output")
print(f"\tThis item is a: {json_in_memory.dataType}")
print(f"\tThis item is located at: {json_in_memory.catalogPath}")
list_fc = arcpy.ListFeatureClasses()
print(f"\n\tBut, when we check our current workspace {arcpy.env.workspace}, it returns no feature classes {list_fc}")