<?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 Can you parse JSON responses?  in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/can-you-parse-json-responses/m-p/373738#M14469</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a geoprocessing service with a bunch of custom errors built in. If an error occurs, I would like to get the error message and return it to the user, but the results of a geoprocessing service are these huge JSON responses. Is there a way to easily parse these?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance, this is the ESRI job failure response, all I want is the line in red below to return the user:&lt;/P&gt;&lt;P&gt;esriJobFailed(j62e4482338eb4149a0f8e9a6e574cd90):{"messages":[{"type":"esriJobMessageTypeInformative","description":"Submitted."},{"type":"esriJobMessageTypeInformative","description":"Executing..."},{"type":"esriJobMessageTypeInformative","description":"Executing (HabitatClassification): HabitatClassification C:\\arcgisserver\\directories\\arcgissystem\\arcgisuploads\\services\\MollyGPTesting\\HabitatClassification.GPServer\\ie6130b0b-b340-47e6-8b46-dcf2926abbe2\\VA_Habitat.gdb.zip AL"},{"type":"esriJobMessageTypeInformative","description":"Start Time: Tue Apr 24 14:44:29 2018"},{"type":"esriJobMessageTypeInformative","description":"Executing (HabitatClassification): HabitatClassification C:\\arcgisserver\\directories\\arcgissystem\\arcgisuploads\\services\\MollyGPTesting\\HabitatClassification.GPServer\\ie6130b0b-b340-47e6-8b46-dcf2926abbe2\\VA_Habitat.gdb.zip AL"},{"type":"esriJobMessageTypeInformative","description":"Start Time: Tue Apr 24 14:44:29 2018"},{"type":"esriJobMessageTypeInformative","description":"Running script HabitatClassification..."},{"type":"esriJobMessageTypeInformative","description":"Executing script \"HabitatClassification\"..."},{"type":"esriJobMessageTypeInformative","description":"Start Time 04/24/2018 14:44.29..."},{"type":"esriJobMessageTypeInformative","description":"c:\\arcgisserver\\directories\\arcgisjobs\\mollygptesting\\habitatclassification_gpserver\\j62e4482338eb4149a0f8e9a6e574cd90\\scratch\\scratch.gdb"},{"type":"esriJobMessageTypeInformative","description":"c:\\arcgisserver\\directories\\arcgisjobs\\mollygptesting\\habitatclassification_gpserver\\j62e4482338eb4149a0f8e9a6e574cd90\\scratch"},{"type":"esriJobMessageTypeInformative","description":"Successfully extracted zip file..."},{"type":"esriJobMessageTypeInformative","description":"c:\\arcgisserver\\directories\\arcgisjobs\\mollygptesting\\habitatclassification_gpserver\\j62e4482338eb4149a0f8e9a6e574cd90\\scratch\\VA_Habitat.gdb"},{"type":"esriJobMessageTypeError","description":"&lt;SPAN style="color: #ff0000; font-size: 22px;"&gt;You have renamed a field from the original template. Please return it to its original state.&lt;/SPAN&gt;"},&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Apr 2018 18:47:47 GMT</pubDate>
    <dc:creator>MKF62</dc:creator>
    <dc:date>2018-04-24T18:47:47Z</dc:date>
    <item>
      <title>Can you parse JSON responses?</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/can-you-parse-json-responses/m-p/373738#M14469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a geoprocessing service with a bunch of custom errors built in. If an error occurs, I would like to get the error message and return it to the user, but the results of a geoprocessing service are these huge JSON responses. Is there a way to easily parse these?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance, this is the ESRI job failure response, all I want is the line in red below to return the user:&lt;/P&gt;&lt;P&gt;esriJobFailed(j62e4482338eb4149a0f8e9a6e574cd90):{"messages":[{"type":"esriJobMessageTypeInformative","description":"Submitted."},{"type":"esriJobMessageTypeInformative","description":"Executing..."},{"type":"esriJobMessageTypeInformative","description":"Executing (HabitatClassification): HabitatClassification C:\\arcgisserver\\directories\\arcgissystem\\arcgisuploads\\services\\MollyGPTesting\\HabitatClassification.GPServer\\ie6130b0b-b340-47e6-8b46-dcf2926abbe2\\VA_Habitat.gdb.zip AL"},{"type":"esriJobMessageTypeInformative","description":"Start Time: Tue Apr 24 14:44:29 2018"},{"type":"esriJobMessageTypeInformative","description":"Executing (HabitatClassification): HabitatClassification C:\\arcgisserver\\directories\\arcgissystem\\arcgisuploads\\services\\MollyGPTesting\\HabitatClassification.GPServer\\ie6130b0b-b340-47e6-8b46-dcf2926abbe2\\VA_Habitat.gdb.zip AL"},{"type":"esriJobMessageTypeInformative","description":"Start Time: Tue Apr 24 14:44:29 2018"},{"type":"esriJobMessageTypeInformative","description":"Running script HabitatClassification..."},{"type":"esriJobMessageTypeInformative","description":"Executing script \"HabitatClassification\"..."},{"type":"esriJobMessageTypeInformative","description":"Start Time 04/24/2018 14:44.29..."},{"type":"esriJobMessageTypeInformative","description":"c:\\arcgisserver\\directories\\arcgisjobs\\mollygptesting\\habitatclassification_gpserver\\j62e4482338eb4149a0f8e9a6e574cd90\\scratch\\scratch.gdb"},{"type":"esriJobMessageTypeInformative","description":"c:\\arcgisserver\\directories\\arcgisjobs\\mollygptesting\\habitatclassification_gpserver\\j62e4482338eb4149a0f8e9a6e574cd90\\scratch"},{"type":"esriJobMessageTypeInformative","description":"Successfully extracted zip file..."},{"type":"esriJobMessageTypeInformative","description":"c:\\arcgisserver\\directories\\arcgisjobs\\mollygptesting\\habitatclassification_gpserver\\j62e4482338eb4149a0f8e9a6e574cd90\\scratch\\VA_Habitat.gdb"},{"type":"esriJobMessageTypeError","description":"&lt;SPAN style="color: #ff0000; font-size: 22px;"&gt;You have renamed a field from the original template. Please return it to its original state.&lt;/SPAN&gt;"},&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Apr 2018 18:47:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/can-you-parse-json-responses/m-p/373738#M14469</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2018-04-24T18:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can you parse JSON responses?</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/can-you-parse-json-responses/m-p/373739#M14470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I figured out a way to do this, even if it's a bit clunky it'll do what I need it to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, you parse the JSON response in javascript using JSON.parse(). This will return an object with properties of messages, jobId, and jobStatus. The messages object may be an array, so you can loop through the array of messages and look for type "esriJobMessageTypeError". These are your error messages. If a message matches that type you can access the "description" which is the actual error message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My code looks a little something like this now:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;function&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;gpJobComplete&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;result&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;log&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;jobStatus &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'('&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;jobId &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;')'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&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 class="keyword token"&gt;var&lt;/SPAN&gt; jsonResults &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; dojo&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;toJson&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;result&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&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 class="keyword token"&gt;var&lt;/SPAN&gt; jsonParsed &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; JSON&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;parse&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;jsonResults&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&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 class="keyword token"&gt;for&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; i &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; i &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; jsonParsed&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;messages&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;length&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt; i&lt;SPAN class="operator token"&gt;++&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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 class="keyword token"&gt;var&lt;/SPAN&gt; message &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; jsonParsed&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;messages&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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 class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;message&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;type &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"esriJobMessageTypeError"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;log&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"My error message: "&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; message&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;description&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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 class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&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 class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:16:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/can-you-parse-json-responses/m-p/373739#M14470</guid>
      <dc:creator>MKF62</dc:creator>
      <dc:date>2021-12-11T17:16:57Z</dc:date>
    </item>
  </channel>
</rss>

