<?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 JSON Unterminated String Error when Submitting HTTP Request in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSON-Unterminated-String-Error-when-Submitting-HTTP-Request/m-p/248874#M48859</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an online application that I can request data extractions from by submitting an HTTP request with the appropriate JSON fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One field (field2) within my JSON payload is a list type and can contain one or more items. The issue that I am facing is that my JMP script functions only if this list has a single item and not if it has two or more.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error that I receive is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"error":"com.google.gson.stream.MalformedJsonException: Unterminated string&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What confuses me is that if I make the same HTTP request with the same JSON payload using Python's request library, the request goes through without an issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems like it may have to do with how JMP is formatting the JSON before it sends the request out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a simplified version of my code for reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;url = "http://www.example_url.com/request";
my_username = "username";
timeout_minutes = 2;

var_field1 = "\!"value1\!"";&lt;BR /&gt;
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&lt;FONT color="#339966"&gt;var_field2 = "\!"value2a\!""; //works&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;//var_field2 = "\!"value2a\!", \!"value2b\!""; //does not work&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
var_field3 = "\!"value3\!"";

payloadJSON = "{\!"test\!":{\!"field1\!":" || var_field1 || ",\!"field2\!":[" || var_field2 || "],\!"field3\!":[" || var_field3 || "]}}";

request = New HTTP Request(
	URL( url ),
	Method( "POST" ),
	Timeout(timeout_minutes*60),
	Headers
	(
		{
			"header_field1": "header_value1",
			"header_field2": "header_value2"
		}
	),
	Username(my_username),
	JSON(payloadJSON)
);
data = request &amp;lt;&amp;lt; Send();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Feb 2020 20:57:21 GMT</pubDate>
    <dc:creator>caseofmondays</dc:creator>
    <dc:date>2020-02-23T20:57:21Z</dc:date>
    <item>
      <title>JSON Unterminated String Error when Submitting HTTP Request</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-Unterminated-String-Error-when-Submitting-HTTP-Request/m-p/248874#M48859</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have an online application that I can request data extractions from by submitting an HTTP request with the appropriate JSON fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One field (field2) within my JSON payload is a list type and can contain one or more items. The issue that I am facing is that my JMP script functions only if this list has a single item and not if it has two or more.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error that I receive is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"error":"com.google.gson.stream.MalformedJsonException: Unterminated string&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What confuses me is that if I make the same HTTP request with the same JSON payload using Python's request library, the request goes through without an issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems like it may have to do with how JMP is formatting the JSON before it sends the request out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a simplified version of my code for reference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;url = "http://www.example_url.com/request";
my_username = "username";
timeout_minutes = 2;

var_field1 = "\!"value1\!"";&lt;BR /&gt;
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&lt;FONT color="#339966"&gt;var_field2 = "\!"value2a\!""; //works&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;//var_field2 = "\!"value2a\!", \!"value2b\!""; //does not work&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
var_field3 = "\!"value3\!"";

payloadJSON = "{\!"test\!":{\!"field1\!":" || var_field1 || ",\!"field2\!":[" || var_field2 || "],\!"field3\!":[" || var_field3 || "]}}";

request = New HTTP Request(
	URL( url ),
	Method( "POST" ),
	Timeout(timeout_minutes*60),
	Headers
	(
		{
			"header_field1": "header_value1",
			"header_field2": "header_value2"
		}
	),
	Username(my_username),
	JSON(payloadJSON)
);
data = request &amp;lt;&amp;lt; Send();&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Feb 2020 20:57:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-Unterminated-String-Error-when-Submitting-HTTP-Request/m-p/248874#M48859</guid>
      <dc:creator>caseofmondays</dc:creator>
      <dc:date>2020-02-23T20:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: JSON Unterminated String Error when Submitting HTTP Request</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-Unterminated-String-Error-when-Submitting-HTTP-Request/m-p/249001#M48892</link>
      <description>&lt;P&gt;Not knowing the values you are using in value1, value2a, value2b, value3, I cannot definitively say what the problem is. Some characters in JSON have to be escaped (like \n, \t, ", ', and so on).&lt;/P&gt;
&lt;P&gt;If possible, you can use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Write(payloadJSON || "\!n");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;after you have concatenated all the values for payloadJSON and see if valid JSON is produced by copy/paste into a JSON Parser like Chrome's JSON Editor Online plugin.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unless it's very simple JSON, I typically use JSL Associative Arrays and use AsJSONExpr to form the JSON. It does the escaping for me. (The JSON message will also take an Associative Array)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your case (the one the doesn't work) I'd write it like this to make sure all the quoting is handled for JSON&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;var_field1 = "\!"value1\!"";
var_field2 = {"\!"value2a\!", \!"value2b\!""};
var_field3 = "\!"value3\!"";


fields = [=&amp;gt;];
fields["field1"] = var_field1;
fields["field2"] = var_field2;
fields["field3"] = var_field3;


payloadJSON = [=&amp;gt;];
payloadJSON["test"] = fields;
payloadJSON = asJSONExpr(payloadJSON);

Write(payloadJSON || "\!n");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 22:19:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-Unterminated-String-Error-when-Submitting-HTTP-Request/m-p/249001#M48892</guid>
      <dc:creator>bryan_boone</dc:creator>
      <dc:date>2020-02-24T22:19:18Z</dc:date>
    </item>
  </channel>
</rss>

