The JSL and video should help answer the question.
/*
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 <= nc, i += 1,
cname = Column( dt, 1 ) << getname; // name from col 1
dt << deletecolumn( 1 ); // col 1 goes away
Column( dt, nc ) << setname( cname ); // col 5 gets the name (was col 6 before delete)
Wait( 1 ); // just for the video
);
Craige