<?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: Saving a table with empty numerical values as JSON results in invalid JSON primitive? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356184#M60607</link>
    <description>&lt;P&gt;I'm quite sure those would have to be changed into null values to be valid JSON.&lt;/P&gt;&lt;P&gt;If you have only two columns you could try converting datatable to associative array and that to JSON (NOTE: Associative Array won't allow duplicate keys. Valid JSON does but not sure how nice it would be to work with duplicated keys)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = New Table( "testEmpty",
	Add Rows( 2 ),
	New Column( "Col1",
		Character,
		"Nominal",
		Set Selected,
		Set Values( {"test", "test1"} )
	),
	New Column( "Col2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [., .] )
	)
);

aa = Associative Array(Column(dt, "Col1"), Column(dt, "Col2"));

json = As JSON Expr(aa);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This would look like this:&lt;/P&gt;&lt;P&gt;"{\!"test\!":null,\!"test1\!":null}"&lt;/P&gt;&lt;P&gt;and if you save it with Save Text File("c:\temp\test.json", json) it will remove those JMP escaped quotes {"test":null,"test1":null}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Feb 2021 20:01:11 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2021-02-04T20:01:11Z</dc:date>
    <item>
      <title>Saving a table with empty numerical values as JSON results in invalid JSON primitive?</title>
      <link>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356068#M60595</link>
      <description>&lt;P&gt;If a save a table with empty values in one of the numerical columns like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Table( "testEmpty",
	Add Rows( 2 ),
	New Column( "Col1",
		Character,
		"Nominal",
		Set Selected,
		Set Values( {"test", "test"} )
	),
	New Column( "Col2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [., .] )
	)
)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as a JSON file, it will result in this:&lt;/P&gt;&lt;PRE&gt;[
 {
  "Col1" : "test",
  "Col2" : &lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;
 },
 {
  "Col1" : "test",
  "Col2" : &lt;FONT color="#FF0000"&gt;.&lt;/FONT&gt;
 }
]&lt;/PRE&gt;&lt;P&gt;Looks like not everybody agrees that this is a valid JSON syntax. If I read this file back to JSON using, let's say, Powershell:&lt;/P&gt;&lt;PRE&gt;$json = Get-Content -Path 'C:\Users\myUser\testEmpty.json' -ErrorAction Stop | ConvertFrom-Json&lt;/PRE&gt;&lt;P&gt;it will error out:&lt;/P&gt;&lt;PRE&gt;ConvertFrom-Json : &lt;FONT color="#FF0000"&gt;Invalid JSON primitive: ..&lt;/FONT&gt;
At C:\Users\myUser\testEmpty.ps1:1 char:118
+ ... \myUser\testEmpty.json' -ErrorAction Stop | ConvertFrom-Json
+                                                          ~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
 &lt;/PRE&gt;&lt;P&gt;Any idea how to fix this? Any options when saving JSON files using scripts? Or the only workaround is to make sure the table doesn't have empty values?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:25:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356068#M60595</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-06-10T23:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Saving a table with empty numerical values as JSON results in invalid JSON primitive?</title>
      <link>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356184#M60607</link>
      <description>&lt;P&gt;I'm quite sure those would have to be changed into null values to be valid JSON.&lt;/P&gt;&lt;P&gt;If you have only two columns you could try converting datatable to associative array and that to JSON (NOTE: Associative Array won't allow duplicate keys. Valid JSON does but not sure how nice it would be to work with duplicated keys)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = New Table( "testEmpty",
	Add Rows( 2 ),
	New Column( "Col1",
		Character,
		"Nominal",
		Set Selected,
		Set Values( {"test", "test1"} )
	),
	New Column( "Col2",
		Numeric,
		"Continuous",
		Format( "Best", 12 ),
		Set Values( [., .] )
	)
);

aa = Associative Array(Column(dt, "Col1"), Column(dt, "Col2"));

json = As JSON Expr(aa);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This would look like this:&lt;/P&gt;&lt;P&gt;"{\!"test\!":null,\!"test1\!":null}"&lt;/P&gt;&lt;P&gt;and if you save it with Save Text File("c:\temp\test.json", json) it will remove those JMP escaped quotes {"test":null,"test1":null}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 20:01:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356184#M60607</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-02-04T20:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Saving a table with empty numerical values as JSON results in invalid JSON primitive?</title>
      <link>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356193#M60608</link>
      <description>Good to know for cases when I indeed have two columns, in my particular case I have many columns though.&lt;BR /&gt;I just changed the column to Character and if there is no number, I put "NA", and deal with that outside of JSL later.</description>
      <pubDate>Thu, 04 Feb 2021 20:20:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356193#M60608</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2021-02-04T20:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Saving a table with empty numerical values as JSON results in invalid JSON primitive?</title>
      <link>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356220#M60613</link>
      <description>&lt;P&gt;Just changing it to character and leaving "empty" value there will most likely work as I would guess it will be replaced with "" and that is valid for JSON.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 21:05:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Saving-a-table-with-empty-numerical-values-as-JSON-results-in/m-p/356220#M60613</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-02-04T21:05:22Z</dc:date>
    </item>
  </channel>
</rss>

