<?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: Failsafe JSON parsing in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/57053#M32005</link>
    <description>&lt;P&gt;I'm glad to hear that this will be changed in 14.1. With these changes I still get the endless "alert popups". Because the data table is millions or rows long, clicking on the OK sometimes crashes JMP14. There's nothing special about the data. In fact I subsetted a small part as a different table and while the same alerts are happening on that, JMP survives the problem. :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, I'm going to find a simple workaround for this. The non-standard JSON comes in a few predictable forms. If I can if-else these conditions it'll work fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 May 2018 21:23:33 GMT</pubDate>
    <dc:creator>burakbagdatli</dc:creator>
    <dc:date>2018-05-15T21:23:33Z</dc:date>
    <item>
      <title>Failsafe JSON parsing</title>
      <link>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/56951#M31949</link>
      <description>&lt;P&gt;I have a string column that has JSON payloads in it. This is the way our partner stores messages from automated machines. The trouble is that their database sometimes gets non-JSON messages so my &lt;STRONG&gt;:payload&lt;/STRONG&gt; column has rows that cannot be parsed to JSON simply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrapped my parse function with a Try block but even then I'm getting an alert for each row that includes non-JSON-compliant string. It even crashes JMP14 fully sometimes. I could ignore errors but that's not a great way of writing robust code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Local(
  { parsed = [=&amp;gt; ""] },
  Try( parsed = Parse JSON( :payload ) );
  parsed;
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This fails so badly. In rows where &lt;STRONG&gt;:payload&lt;/STRONG&gt; is empty instead of having a JSON string, it returns a "." for some reason. I have no idea where the dot comes from.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to use JSON parsing functions in a failsafe manner? Any help is appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Note:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Here's some examples of the kinds of JSON that I'm dealing with and they get parsed properly:&lt;/P&gt;&lt;P&gt;{"assetId":"AthensPaintLineMotor4",&lt;BR /&gt;"dataItemId":"Temperature1",&lt;BR /&gt;"dateTime":"2018-02-22T19:44:41",&lt;BR /&gt;"value":"91.51"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{"assetId":"OKUMA-Genos-2","dateTime":"2018-04-30T11:59:13","dataItemId":"Lp1block","dataItemName":"p1block","value":"UNAVAILABLE"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{"assetId":"OKUMA-Genos-2","dateTime":"2018-04-30T11:59:13","dataItemId":"Lp1MacManPanelHistory","dataItemName":"p1MacManPanelHistory","value":"2018/04/30 07:58:12 @Change Window:[26026]"}&lt;/P&gt;</description>
      <pubDate>Sun, 13 May 2018 17:43:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/56951#M31949</guid>
      <dc:creator>burakbagdatli</dc:creator>
      <dc:date>2018-05-13T17:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Failsafe JSON parsing</title>
      <link>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/56967#M31956</link>
      <description>&lt;P&gt;Some of this is fixed in the upcoming 14.1 maintenance. If you have data that crashes JMP and can share it, that would help. Here's a work around for now:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;payload = "\[
	{
]\"; // malformed JSON
Try(
	txt = Log Capture( result = Parse JSON( payload ) );
	If( Length( txt ),
		Throw( txt ) // error message
	);
	result; // parsed JSON
,
	Show( exception_msg );
	"?" // returned value for malformed JSON
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works by using the &lt;EM&gt;LogCapture&lt;/EM&gt; function to capture any log output from the &lt;EM&gt;Parse JSON&lt;/EM&gt; function and throwing that as an error. The &lt;EM&gt;Show&lt;/EM&gt;(...) is optional; &lt;EM&gt;exception_msg&lt;/EM&gt; is a special variable with the value that was thrown, either by &lt;EM&gt;throw(txt)&lt;/EM&gt; or by JMP for some other error.&lt;/P&gt;
&lt;P&gt;The "?" could be replaced by [ =&amp;gt; ] or some other value that makes sense to you.&lt;/P&gt;
&lt;P&gt;In the payload string I used the raw string quotes "\[ and ]\" so I would not need to escape quotation marks in my test data. You don't need that for data already in a data table.&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 11:46:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/56967#M31956</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-05-14T11:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Failsafe JSON parsing</title>
      <link>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/57053#M32005</link>
      <description>&lt;P&gt;I'm glad to hear that this will be changed in 14.1. With these changes I still get the endless "alert popups". Because the data table is millions or rows long, clicking on the OK sometimes crashes JMP14. There's nothing special about the data. In fact I subsetted a small part as a different table and while the same alerts are happening on that, JMP survives the problem. :)&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, I'm going to find a simple workaround for this. The non-standard JSON comes in a few predictable forms. If I can if-else these conditions it'll work fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 21:23:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/57053#M32005</guid>
      <dc:creator>burakbagdatli</dc:creator>
      <dc:date>2018-05-15T21:23:33Z</dc:date>
    </item>
    <item>
      <title>Re: Failsafe JSON parsing</title>
      <link>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/57073#M32019</link>
      <description>&lt;P&gt;Try the Batch Interactive solution&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2610"&gt;@vince_faller&lt;/a&gt;&amp;nbsp;discussed &lt;A href="https://community.jmp.com/t5/Discussions/Open-Database-Errors/m-p/20876" target="_blank"&gt;here&lt;/A&gt;. (And&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/1947"&gt;@Eric_Hill&lt;/a&gt;&amp;nbsp;reply.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Scriptscriptscriptscript;
Batch Interactive(1);
DatabaseCall;
Batch Interactive(0);
MoreScriptScriptScript&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 May 2018 09:22:00 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Failsafe-JSON-parsing/m-p/57073#M32019</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-05-16T09:22:00Z</dc:date>
    </item>
  </channel>
</rss>

