<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Output json from Geoprocessing script? in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/output-json-from-geoprocessing-script/m-p/658960#M21955</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Actually, the script was using json.dumps from the beginning with string as the output type, but when I ran it initially, there was no output so I had removed the json conversion and started looking at using some other form of data structure.&amp;nbsp; Basically the problem came down to not understanding the ESRI way of doing things even after reading the docs.&amp;nbsp; The json as a string works fine.&amp;nbsp; The reason the output was empty was simply because I did not know you had to use setparameter no matter what.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will mark your post as helpful because even though it was not the answer, it put me back on the right track, so thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Jun 2014 20:10:35 GMT</pubDate>
    <dc:creator>NeoGeo</dc:creator>
    <dc:date>2014-06-10T20:10:35Z</dc:date>
    <item>
      <title>Output json from Geoprocessing script?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/output-json-from-geoprocessing-script/m-p/658958#M21953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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).&amp;nbsp; Is there some other multiple value data structure that a geoprocessing script can handle that I can use to output my data?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I have tried, is setting the output parameter to multivalue with type "any value" and using this code:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;results=arcpy.SetParameter(5,';'.join(record_list))&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;but it fails saying it is expecting strings because my data is a list of dictionaries not a list of strings.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My output data is in this format:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[{'layer': 'Wombat Habitat', 'value': '-999'}, {'layer': 'Purple People Eater Habitat', 'value': '7.65'}, {'layer': 'Cookie Monster Habitat', 'value': '3.03'}]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Background info:&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; 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).&amp;nbsp; 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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Jun 2014 03:29:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/output-json-from-geoprocessing-script/m-p/658958#M21953</guid>
      <dc:creator>NeoGeo</dc:creator>
      <dc:date>2014-06-07T03:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: Output json from Geoprocessing script?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/output-json-from-geoprocessing-script/m-p/658959#M21954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;SPAN&gt;Set your output as string and use the json.dumps function - &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://docs.python.org/2/library/json.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://docs.python.org/2/library/json.html&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import json
output_str = json.dumps(output_dict)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:53:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/output-json-from-geoprocessing-script/m-p/658959#M21954</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-12T03:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Output json from Geoprocessing script?</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/output-json-from-geoprocessing-script/m-p/658960#M21955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Actually, the script was using json.dumps from the beginning with string as the output type, but when I ran it initially, there was no output so I had removed the json conversion and started looking at using some other form of data structure.&amp;nbsp; Basically the problem came down to not understanding the ESRI way of doing things even after reading the docs.&amp;nbsp; The json as a string works fine.&amp;nbsp; The reason the output was empty was simply because I did not know you had to use setparameter no matter what.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will mark your post as helpful because even though it was not the answer, it put me back on the right track, so thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Jun 2014 20:10:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/output-json-from-geoprocessing-script/m-p/658960#M21955</guid>
      <dc:creator>NeoGeo</dc:creator>
      <dc:date>2014-06-10T20:10:35Z</dc:date>
    </item>
  </channel>
</rss>

