AnsweredAssumed Answered

Output json from Geoprocessing script?

Question asked by NeoGeo on Jun 6, 2014
Latest reply on Jun 10, 2014 by NeoGeo
I do not see any way to make a 10.2 geoprocessing script return data in json format (no json option in output parameter data types).  Is there some other multiple value data structure that a geoprocessing script can handle that I can use to output my data?

What I have tried, is setting the output parameter to multivalue with type "any value" and using this code:            
results=arcpy.SetParameter(5,';'.join(record_list))

but it fails saying it is expecting strings because my data is a list of dictionaries not a list of strings. 

My output data is in this format:
[{'layer': 'Wombat Habitat', 'value': '-999'}, {'layer': 'Purple People Eater Habitat', 'value': '7.65'}, {'layer': 'Cookie Monster Habitat', 'value': '3.03'}]

Background info:  This was originally a standalone REST service which output json that was consumed by a Flex widget that I have rewritten as a Python script because previous versions are no longer supported for various reasons I won't get into here.  I wrote the new Python version as a standalone RESTful service but was running into problems with ArcPy memory leaks, which would not matter if the script ended but are a major problem for a service that does not end.  At this point I am trying to just make it into a Geoprocessing script to be published as a service and just modify the widget to consume from thatGP service instead of a normal standalone REST service because I am guessing the GP service will execute it as if it was a normal script which would end (therefore getting memory back).  In case you are wondering about the memory leaks, I did try using del statements, with statements, and putting as much as I could in functions to free up memory but it just keeps growing every time the service gets called.

Thank you!

Outcomes