<?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 &amp;lt;=&amp;gt; JMP in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420462#M66926</link>
    <description>&lt;P&gt;I would guess it&amp;nbsp;&amp;nbsp;should use generic names like "Column1" then or if done through GUI just have option to input it.&lt;/P&gt;&lt;P&gt;I think it should have an option to say - everything from level 1 goes to this column, everything from level 2 goes to that column, and so on...&lt;/P&gt;</description>
    <pubDate>Wed, 22 Sep 2021 21:21:46 GMT</pubDate>
    <dc:creator>miguello</dc:creator>
    <dc:date>2021-09-22T21:21:46Z</dc:date>
    <item>
      <title>JSON &lt;=&gt; JMP</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420363#M66918</link>
      <description>&lt;P&gt;All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a 2 part question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Part 1.&lt;/P&gt;&lt;P&gt;Let's say I have a JSON file of this kind:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;[
    {
        "Cat1":  {
			"SubCat1": {
				"Param1": "AA", 
				"Param2": "BB" 
			},
			"SubCat2": {
					"Param1": "AB", 
					"Param2": "BC" 
				}
		},
        "Cat2":  {
			"SubCat1": {
				"Param1": "BA", 
				"Param2": "BC" 
			},
			"SubCat2": {
					"Param1": "CB", 
					"Param2": "BD"
				}
		}
    }
]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How would I import it to JMP (using GUI or scripts) to get something like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JMP.png" style="width: 297px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36009i759297EAD83674F7/image-size/large?v=v2&amp;amp;px=999" role="button" title="JMP.png" alt="JMP.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So far I'm just getting bunch of columns and one row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Part 2.&lt;/P&gt;&lt;P&gt;Now I need to convert JMP table to JSON file. Let's say I have a JMP file that looks like above. Simple saving it as JSON would lead to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;[
 {
  "Category" : "Cat1",
  "SubCategory" : "SubCat1",
  "Parameter" : "Param1",
  "Value" : "AA"
 },
 {
  "Category" : "Cat1",
  "SubCategory" : "SubCat1",
  "Parameter" : "Param2",
  "Value" : "BB"
 },
 {
  "Category" : "Cat1",
  "SubCategory" : "SubCat2",
  "Parameter" : "Param1",
  "Value" : "AB"
 },
 {
  "Category" : "Cat1",
  "SubCategory" : "SubCat2",
  "Parameter" : "Param2",
  "Value" : "BC"
 },
 {
  "Category" : "Cat2",
  "SubCategory" : "SubCat1",
  "Parameter" : "Param1",
  "Value" : "BA"
 },
 {
  "Category" : "Cat2",
  "SubCategory" : "SubCat1",
  "Parameter" : "Param2",
  "Value" : "BC"
 },
 {
  "Category" : "Cat2",
  "SubCategory" : "SubCat2",
  "Parameter" : "Param1",
  "Value" : "CB"
 },
 {
  "Category" : "Cat2",
  "SubCategory" : "SubCat2",
  "Parameter" : "Param2",
  "Value" : "BD"
 }
]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which is not good.&lt;/P&gt;&lt;P&gt;But if I construct an AA that looks like this and save it as JSON:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;AA = [
	        "Cat1"=&amp;gt;  [
			"SubCat1"=&amp;gt; [
				"Param1"=&amp;gt; "AA", 
				"Param2"=&amp;gt; "BB" 
			],
			"SubCat2"=&amp;gt; [
					"Param1"=&amp;gt; "AB", 
					"Param2"=&amp;gt; "BC" 
				]
		],
        "Cat2"=&amp;gt;  [
			"SubCat1"=&amp;gt; [
				"Param1"=&amp;gt; "BA", 
				"Param2"=&amp;gt; "BC" 
			],
			"SubCat2"=&amp;gt; [
					"Param1"=&amp;gt; "CB", 
					"Param2"=&amp;gt; "BD"
				]
		]
    ];
    
JSON = As JSON Expr(AA);

Save Text File("C:\Users\MyUser\JMPtoJSON\AAtoJSON.json", JSON)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;then I get JSON I need.&lt;/P&gt;&lt;P&gt;Question - what is the most efficient way of constructing AA like that from JMP table like that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:37:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420363#M66918</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-06-10T23:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: JSON &lt;=&gt; JMP</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420460#M66925</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;At first glance, your original JSON file does not include any column header which my confuse JMP JSON import routine. Just a thought.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;TS&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 20:58:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420460#M66925</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2021-09-22T20:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: JSON &lt;=&gt; JMP</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420462#M66926</link>
      <description>&lt;P&gt;I would guess it&amp;nbsp;&amp;nbsp;should use generic names like "Column1" then or if done through GUI just have option to input it.&lt;/P&gt;&lt;P&gt;I think it should have an option to say - everything from level 1 goes to this column, everything from level 2 goes to that column, and so on...&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 21:21:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420462#M66926</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2021-09-22T21:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: JSON &lt;=&gt; JMP</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420478#M66929</link>
      <description>&lt;P&gt;part 1 answer&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1 = Open(
	Char To Blob(
		"\[[
    {
        "Cat1":  {
			"SubCat1": {
				"Param1": "AA", 
				"Param2": "BB" 
			},
			"SubCat2": {
					"Param1": "AB", 
					"Param2": "BC" 
				}
		},
        "Cat2":  {
			"SubCat1": {
				"Param1": "BA", 
				"Param2": "BC" 
			},
			"SubCat2": {
					"Param1": "CB", 
					"Param2": "BD"
				}
		}
    }
]]\"
	),
	json
);

dt2 = dt1 &amp;lt;&amp;lt; Transpose(	columns( dt1 &amp;lt;&amp;lt; getcolumnnames ) ); // the 8 columns become the 8 rows
name = {"category", "SubCategory", "Parameter"}; // add these new column names
For( i = 1, i &amp;lt;= nitems(name), i += 1,
	nc = dt2 &amp;lt;&amp;lt; New Column( name[i], formula( Word( i, label, "." ) ) );
	dt2 &amp;lt;&amp;lt; runformulas; // run, 
	nc &amp;lt;&amp;lt; deleteformula(); // and remove so label is no longer referenced
);
// pretty it up...
dt2:row1 &amp;lt;&amp;lt; setname( "value" );
dt2 &amp;lt;&amp;lt; deletecolumns( label ); // unreferenced now, and not needed
// move value to end if desired...
dt2:value &amp;lt;&amp;lt; setselected; dt2 &amp;lt;&amp;lt; move selected columns( to last ); dt2 &amp;lt;&amp;lt; Clear Column Selection(); &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The import table has the data, in one row, but encoded into the column names. After transposing, use the word() function in a column formula to split the dotted name into 3 columns. Remove the formula so the label column can be removed since it is now redundant.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="transposed and column-ized" style="width: 664px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/36018iB41BD402A4774A1D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="transposed and column-ized" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;transposed and column-ized&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 22:28:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420478#M66929</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-09-22T22:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: JSON &lt;=&gt; JMP</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420482#M66930</link>
      <description>&lt;P&gt;part 2, using dt2 from part 1. For each row, create the key+AA if not already created, then add the next level key. This will keep the last occurrence of a duplicated row.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;result = [=&amp;gt; ];
For( i = 1, i &amp;lt;= N Rows( dt2 ), i += 1,
	If( !Contains( result, dt2:category[i] ),
		result[dt2:category[i]] = [=&amp;gt; ]
	);
	If( !Contains( result[dt2:category[i]], dt2:SubCategory[i] ),
		result[dt2:category[i]][dt2:SubCategory[i]] = [=&amp;gt; ]
	);
	result[dt2:category[i]][dt2:SubCategory[i]][dt2:Parameter[i]] = dt2:value[i];
);
Write( As JSON Expr( result ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; "Cat1":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "SubCat1":{"Param1":"AA","Param2":"BB"},&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "SubCat2":{"Param1":"AB","Param2":"BC"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; "Cat2":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "SubCat1":{"Param1":"BA","Param2":"BC"},&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "SubCat2":{"Param1":"CB","Param2":"BD"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 23:05:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420482#M66930</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-09-22T23:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: JSON &lt;=&gt; JMP</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420485#M66931</link>
      <description>&lt;P&gt;As &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11634"&gt;@Thierry_S&lt;/a&gt;&amp;nbsp; pointed out, the JSON format is using &lt;EM&gt;data&lt;/EM&gt; rather than &lt;EM&gt;names&lt;/EM&gt; for keys. Your example of JMP's preferred save-to-json uses the column &lt;EM&gt;names&lt;/EM&gt; for the keys.&lt;/P&gt;&lt;P&gt;Pandas JSON formats can squeeze out some of the redundancy, and JMP can read them (but not directly write them. &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/1893"&gt;@Audrey_Shull&lt;/a&gt;&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 23:24:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420485#M66931</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-09-22T23:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: JSON &lt;=&gt; JMP</title>
      <link>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420486#M66932</link>
      <description>&lt;P&gt;Thanks, Craig,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good hint for me to use&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;!Contains()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I started creating AAs for each column and getting keys to get unique values for that particular level&amp;nbsp; to iterate over them and made it too complicated. Your method is much simpler.&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;</description>
      <pubDate>Wed, 22 Sep 2021 23:31:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSON-lt-gt-JMP/m-p/420486#M66932</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2021-09-22T23:31:08Z</dc:date>
    </item>
  </channel>
</rss>

