<?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: How to load the JSON data into a data table with proper column name？ in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627849#M82625</link>
    <description>&lt;P&gt;Thank you for so detailed illustration with video.&amp;nbsp;&lt;SPAN&gt;The ingenious idea and clever code have implemented the functionality I need so powerfully.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you like to pay more effort to give me some help about "stack()"? I don't know the concept of "stack()" and the difference among the argument 0 or 1 or any other values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 May 2023 04:41:28 GMT</pubDate>
    <dc:creator>sheephut</dc:creator>
    <dc:date>2023-05-02T04:41:28Z</dc:date>
    <item>
      <title>How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627675#M82617</link>
      <description>&lt;P&gt;I want to know how to load a file with the following JSON data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;{
  "ErrorCode": 0,
  "ResultSets": [
    {
      "ColName": [
        "date",
        "name",
        "ZQDM",
        "sc",
        "content"
      ],
      "Content": [
        [
          "20230428",
          "*ST和科",
          "002816",
          0,
          "由和科达变为*ST和科"
        ],
        [
          "20230428",
          "*ST弘高",
          "002504",
          0,
          "由ST弘高变为*ST弘高"
        ],
        [
          "20230428",
          "*ST明诚",
          "600136",
          1,
          "由ST明诚变为*ST明诚"
        ],
        [
          "20230428",
          "*ST碳元",
          "603133",
          1,
          "由碳元科技变为*ST碳元"
        ],
        [
          "20230428",
          "*ST西域",
          "300859",
          0,
          "由西域旅游变为*ST西域"
        ],
        [
          "20230428",
          "ST天顺",
          "002800",
          0,
          "由天顺股份变为ST天顺"
        ],
        [
          "20230428",
          "ST宇顺",
          "002289",
          0,
          "由宇顺电子变为ST宇顺"
        ],
        [
          "20230428",
          "ST贵人",
          "603555",
          1,
          "由贵人鸟变为ST贵人"
        ],
        [
          "20230428",
          "ST迪威迅",
          "300167",
          0,
          "由迪威迅变为ST迪威迅"
        ]
      ]
    }
  ]
}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;The&amp;nbsp;effective data is the node of "/root/ResultSets/", it is composed by two parts, the first part is the list of the columns' name as the node "/root/ResultSets/ColName", the second part is the body of the data table as the node "/root/ResultSets/Content", depicted by a&amp;nbsp;two-dimension JSON datum.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I used the following JSON Settings in open file function, but cannot set the columns'name with the data in node&amp;nbsp;&lt;SPAN&gt;"/root/ResultSets/ColName".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	JSON Settings(
		Stack( 0 ),
		Col(
			"/root/ResultSets/Content",
			Column Name( "Content" ),
			Fill( "Use Once" ),
			Type( "Pandas Values" ),
			Format( {"Best"} ),
			Modeling Type( "Continuous" )
		)
	),&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know how to load the JSON data into a data table with proper column name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 00:00:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627675#M82617</guid>
      <dc:creator>sheephut</dc:creator>
      <dc:date>2023-06-11T00:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627843#M82624</link>
      <description>&lt;P&gt;The JSL and video should help answer the question.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;/*
There are two kinds of JSON: 
o  The good kind: the keys are the names of the data. A good kind example has 
   a key named "date" with date values for the data.
o  The bad kind: the keys are data values. A bad kind example has a huge 
   number of different keys with names 1jan2020, 2jan2020... JMP does not 
   have a great way to import the bad kind.

This example is a good kind example. It does not quite match one
of the standard pandas formats or the standard rows-with-headers format.
But it is not abusing keys to hold data, so it can be made to work.
 
It could be treated as two tables with some JSL to make a minor fixup.
o  a table of one colname per row, and
o  a table of rows of 5 items each.

Or it can be treated as one table with some JSL to make a minor fix up.
The fixup JSL here is for the one table case; the two table case needs
a simpler version to rename the columns.
*/

j =
"\[
	{
  "ErrorCode": 0,"ResultSets": [
    {
      "ColName": [ "date","name","ZQDM","sc","content" ],
      "Content": [
		["20230428","*ST和科","002816",0,"由和科达变为*ST和科"],
		["20230428","*ST弘高","002504",0,"由ST弘高变为*ST弘高"],
		["20230428","*ST明诚","600136",1,"由ST明诚变为*ST明诚"],
		["20230428","*ST碳元","603133",1,"由碳元科技变为*ST碳元"],
		["20230428","*ST西域","300859",0,"由西域旅游变为*ST西域"],
		["20230428","ST天顺","002800",0,"由天顺股份变为ST天顺"],
		["20230428","ST宇顺","002289",0,"由宇顺电子变为ST宇顺"],
		["20230428","ST贵人","603555",1,"由贵人鸟变为ST贵人"],
		["20230428","ST迪威迅","300167",0,"由迪威迅变为ST迪威迅"]
      ]
    }
  ]
}
]\";

// there are two ways: save text file, then open, OR convert to blob, then open

//open(chartoblob(j),jsonwizard(1));
// or...
file = Save Text File( "$temp/x.json", j );
Open( file, jsonwizard( 1 ) );

// at this point, watch the video. the json settings section is the copy/paste from the video.
// Or, you could let the wizard finish importing and grab the complete script from the table.
// either way, the fix up step below is still needed because the shape of the JSON is not quite
// right for the wizard to do a perfect job.

dt = JSON To Data Table(
	j, 
 // paste here
	JSON Settings(
		Stack( 1 ),
		Col(
			"/root/ResultSets/ColName",
			Column Name( "ColName" ),
			Fill( "Use Once" ),
			Type( "JSON Lines with Headers" ),
			Format( {"Best"} ),
			Modeling Type( "Continuous" )
		),
		Col(
			"/root/ResultSets/Content",
			Column Name( "Content" ),
			Fill( "Use Once" ),
			Type( "Pandas Values" ),
			Format( {"Best"} ),
			Modeling Type( "Continuous" )
		)
	)
);

// fix up. the first 5 columns have the name, but no data
// the last 5 columns have the data but the wrong name.
nc = N Cols( dt ) / 2; // get number of cols. the first half are the names, the second half are the data.
For( i = 1, i &amp;lt;= nc, i += 1,
	cname = Column( dt, 1 ) &amp;lt;&amp;lt; getname; // name from col 1
	dt &amp;lt;&amp;lt; deletecolumn( 1 ); // col 1 goes away
	Column( dt, nc ) &amp;lt;&amp;lt; setname( cname ); // col 5 gets the name (was col 6 before delete)
	Wait( 1 ); // just for the video
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6326589419112w600h338r182" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6326589419112" data-account="6058004218001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6058004218001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6326589419112w600h338r182');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://community.jmp.com/t5/video/gallerypage/video-id/6326589419112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 01:40:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627843#M82624</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-02T01:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627849#M82625</link>
      <description>&lt;P&gt;Thank you for so detailed illustration with video.&amp;nbsp;&lt;SPAN&gt;The ingenious idea and clever code have implemented the functionality I need so powerfully.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would you like to pay more effort to give me some help about "stack()"? I don't know the concept of "stack()" and the difference among the argument 0 or 1 or any other values?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 04:41:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627849#M82625</guid>
      <dc:creator>sheephut</dc:creator>
      <dc:date>2023-05-02T04:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627914#M82628</link>
      <description>&lt;P&gt;Stack is a boolean checkbox in the GUI, 0 is unchecked, 1 is checked. Sometimes the data is organized in a way that it is better checked, or maybe better unchecked. With your data:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="stack(0) the data goes across" style="width: 742px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52503iB8F0CC3CF15AEC5F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="stack(0) the data goes across" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;stack(0) the data goes across&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="stack(1) the data goes down" style="width: 744px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52504iB1F221B6AAFE1AE2/image-size/large?v=v2&amp;amp;px=999" role="button" title="capture2.png" alt="stack(1) the data goes down" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;stack(1) the data goes down&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In this example, ResultSet is the key selected to generate rows. That means each time a ResultSet key is closed, row(s) will be generated. In this example there is only one ResultSet key, so there is only one time when it closes.&amp;nbsp; ColName is the key chosen to make columns. The five values will all be in the same cell of a single row for stack(0). For stack(1), multiple rows are generated each time the ResultSet key is closed. If there are multiple stackable columns with stack(1), their values are emitted in parallel when the ResultSet key is closed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are several columns with the same number of values, stack(1) is very useful. If there is only one column, and you do it like this, stack makes no difference:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Using ColName to create the rows and the column" style="width: 716px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52505iC5872DDF80AB3DC8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture3.PNG" alt="Using ColName to create the rows and the column" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Using ColName to create the rows and the column&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The ColName now generates a row for each new value it finds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Fill parameter is also related to this. Add the ErrorCode:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ErrorCode added with 'use once'" style="width: 643px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52506i5508737E65441F08/image-size/large?v=v2&amp;amp;px=999" role="button" title="capture4.png" alt="ErrorCode added with 'use once'" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;ErrorCode added with 'use once'&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ErrorCode with 'Use Forever'." style="width: 683px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52507iAE63F4C765AAB299/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture5.PNG" alt="ErrorCode with 'Use Forever'." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;ErrorCode with 'Use Forever'.&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 11:30:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/627914#M82628</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-02T11:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/628116#M82646</link>
      <description>&lt;P class=""&gt;&lt;SPAN class=""&gt;I'm still using JMP 14&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;As if JSL doesn't work like this, how can such structured data be quickly converted to tables using the convert to blob method?&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;Thank Craige!&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2023-05-03_16-30-41.png" style="width: 471px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52521iD9F6F93A5206C382/image-size/large?v=v2&amp;amp;px=999" role="button" title="2023-05-03_16-30-41.png" alt="2023-05-03_16-30-41.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 08:33:48 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/628116#M82646</guid>
      <dc:creator>lwx228</dc:creator>
      <dc:date>2023-05-03T08:33:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/628138#M82648</link>
      <description>&lt;P&gt;The XML and JSON import wizard first appeared in JMP 15.&lt;/P&gt;
&lt;P&gt;JMP 14 probably had some JSON import capability, but does not support the extended syntax the wizard uses.&lt;/P&gt;
&lt;P&gt;Depending on the JSON file, JMP 14's support might be good enough.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JSON To DataTable will work for some strings well enough." style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52523iCCE35AEEA6402AE7/image-size/large?v=v2&amp;amp;px=999" role="button" title="capture.png" alt="JSON To DataTable will work for some strings well enough." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;JSON To DataTable will work for some strings well enough.&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I think XML support is not in 14 except through the XML parsing functions.&lt;/P&gt;
&lt;P&gt;JMP 14 can open from a blob, like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;open(chartoblob("a,b,c\!n1,2,3"),"text")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but only for the file types it understands. For some reason, "text" files mean CSV files...&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 11:12:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/628138#M82648</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-03T11:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/656939#M84593</link>
      <description>&lt;P&gt;If this JSON data is downloaded via POST, how can I convert this data from JSON to table data in memory without first saving it as a local file?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;rs = New HTTP Request( URL( u ), Method( "POST" ), JSON( jj ), Headers( h ) );
rr = rs &amp;lt;&amp;lt; Send;&lt;BR /&gt;//？？&lt;BR /&gt;&lt;BR /&gt;dt=Open(chartoblob( rr ),"json",JSON Settings(Stack(0),Row("/root/data"),Col("/root/data",Fill("Use Once"),Type("Pandas Values") )),JSON Wizard(0));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank Craige!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 14:06:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/656939#M84593</guid>
      <dc:creator>UersK</dc:creator>
      <dc:date>2023-07-10T14:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to load the JSON data into a data table with proper column name？</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/657063#M84608</link>
      <description>&lt;P&gt;jsonToDataTable(), if you like what it does.&lt;/P&gt;
&lt;P&gt;Or use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;open( chartoblob( text ), json wizard options )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To use the wizard, save an example table to disk, run the wizard, grab the script and modify the filename in the open to be chartoblob(json text).&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2023 18:25:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-load-the-JSON-data-into-a-data-table-with-proper-column/m-p/657063#M84608</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-07-10T18:25:49Z</dc:date>
    </item>
  </channel>
</rss>

