<?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: JSON.parse not parsing the string in ThingWorx Developers</title>
    <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598626#M34942</link>
    <description>&lt;P&gt;Hello Paichung,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to accomplish? - I want to create JSON for the row Data in grid. I cannot use Infotable as the headers I need for the result table have special characters and spaces and are changing continuously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am creating the string using the data from 2 tables within a service.&lt;/P&gt;
&lt;P&gt;And then using JSON.parse on that string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried your suggestion too. Created a Input Parameter with baseType as JSON and assigned the string variable to it. and passed to result with baseType set as JSON.&lt;/P&gt;
&lt;P&gt;Also This time, I added logger.warn() to create log messages.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;One Thing I noticed, the service execution is completed, but the window keeps on showing Executing bar continuously. Same happened when I tried with JSON.parse() and your method too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This clears that there is no issue with the JSON.parse(), actually the Executing message that appears continuously.&lt;BR /&gt;How can I make sure, that this will not affect when using in mashups anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Bhushan&lt;/P&gt;</description>
    <pubDate>Fri, 15 Mar 2019 07:02:47 GMT</pubDate>
    <dc:creator>bdeshmukh</dc:creator>
    <dc:date>2019-03-15T07:02:47Z</dc:date>
    <item>
      <title>JSON.parse not parsing the string</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598096#M34794</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I am creating a string using concatenation of different data needed and creating the result string as below.&lt;/P&gt;
&lt;P&gt;{"rows":[{ "id":1, "data":["Tr1",80.35,79.27]},{ "id":2, "data":["Tr2",7.24,19.34]},{ "id":3, "data":["Tr3",16.02,77.20]},{ "id":4, "data":["Tr4",44.12,51.64]},{ "id":5, "data":["Tr5",30.72,93.91]}]}&lt;/P&gt;
&lt;P&gt;This input to JSON.parse(); gives error as "unexpected object literal".&lt;BR /&gt;I understand that, when the string is passed to the JSON.parse it will be in double quotes, as below&lt;/P&gt;
&lt;P&gt;"{"rows":[{ "id":1, "data":["Tr1",80.35,79.27]},{ "id":2, "data":["Tr2",7.24,19.34]},{ "id":3, "data":["Tr3",16.02,77.20]},{ "id":4, "data":["Tr4",44.12,51.64]},{ "id":5, "data":["Tr5",30.72,93.91]}]}"&lt;/P&gt;
&lt;P&gt;and this will fail as invalid JSON. So I am passing the string with a backslash as a prefix to the double quotes as ( \" ). so that my result String would be.&lt;/P&gt;
&lt;P&gt;"{\"rows\":[{ \"id\":1, \"data\":[\"Tr1\",80.35,79.27]},{ \"id\":2, \"data\":[\"Tr2\",7.24,19.34]},{ \"id\":3, \"data\":[\"Tr3\",16.02,77.20]},{ \"id\":4, \"data\":[\"Tr4\",44.12,51.64]},{ \"id\":5, \"data\":[\"Tr5\",30.72,93.91]}]}"&lt;/P&gt;
&lt;P&gt;Even this fails JSON.parse() or service keeps showing the "Executing" status. However when this same string is parsed in browser's console, it parses successfully.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;In addition to above, I cannot create an Infotable and then convert it to JSON, because the column names that I have include spaces and special characters. And Thingworx doesn't accept Field Names for Datashape with Special Characters and spaces..&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Bhushan&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2019 07:19:09 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598096#M34794</guid>
      <dc:creator>bdeshmukh</dc:creator>
      <dc:date>2019-03-13T07:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: JSON.parse not parsing the string</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598437#M34840</link>
      <description>&lt;P&gt;What exactly are you trying to accomplish?&lt;/P&gt;
&lt;P&gt;How is this string being put into Thingworx?&lt;/P&gt;
&lt;P&gt;I think if you have a service that had an input parameter of JSON and you input the original string, it should automatically be interpreted as a JSON object within Thingworx and you wouldn't need to JSON.parse it.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 13:57:30 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598437#M34840</guid>
      <dc:creator>PaiChung</dc:creator>
      <dc:date>2019-03-14T13:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: JSON.parse not parsing the string</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598626#M34942</link>
      <description>&lt;P&gt;Hello Paichung,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to accomplish? - I want to create JSON for the row Data in grid. I cannot use Infotable as the headers I need for the result table have special characters and spaces and are changing continuously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am creating the string using the data from 2 tables within a service.&lt;/P&gt;
&lt;P&gt;And then using JSON.parse on that string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried your suggestion too. Created a Input Parameter with baseType as JSON and assigned the string variable to it. and passed to result with baseType set as JSON.&lt;/P&gt;
&lt;P&gt;Also This time, I added logger.warn() to create log messages.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;One Thing I noticed, the service execution is completed, but the window keeps on showing Executing bar continuously. Same happened when I tried with JSON.parse() and your method too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This clears that there is no issue with the JSON.parse(), actually the Executing message that appears continuously.&lt;BR /&gt;How can I make sure, that this will not affect when using in mashups anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Bhushan&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 07:02:47 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598626#M34942</guid>
      <dc:creator>bdeshmukh</dc:creator>
      <dc:date>2019-03-15T07:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: JSON.parse not parsing the string</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598689#M34954</link>
      <description>&lt;P&gt;I'm not quite sure how you are doing this, but&lt;/P&gt;
&lt;P&gt;the following piece works just fine (output of service is string)&lt;/P&gt;
&lt;P&gt;var myString = JSON.parse('{"rows": [{"id": 1,"data": ["Tr1", 80.35, 79.27] }, {"id": 2,"data": ["Tr2", 7.24, 19.34]}]}')&lt;BR /&gt;result = myString.rows[0].data[1];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and my output is 80.35&lt;/P&gt;
&lt;P&gt;So you should be able to iterate the object and construct an infotable.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 13:40:52 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/598689#M34954</guid>
      <dc:creator>PaiChung</dc:creator>
      <dc:date>2019-03-15T13:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: JSON.parse not parsing the string</title>
      <link>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/601913#M35034</link>
      <description>&lt;P&gt;Hello Paichung,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It was working for me too, but I didn't know that until I added the statements to create log entries in the service code.&lt;BR /&gt;For me the service used to execute successfully, but the output was not displayed, instead the Service executing message kept displaying even after the execution completed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Bhushan&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 06:53:48 GMT</pubDate>
      <guid>https://www.ptcusercommunity.com/t5/ThingWorx-Developers/JSON-parse-not-parsing-the-string/m-p/601913#M35034</guid>
      <dc:creator>bdeshmukh</dc:creator>
      <dc:date>2019-03-19T06:53:48Z</dc:date>
    </item>
  </channel>
</rss>

