cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
vishwasanj
Level V

.json file to trend charts

I have been following Craige and Xan's JSON parser document. I am using JMP 13.

https://community.jmp.com/t5/JMP-Scripts/JSON-Parsing-Functions/ta-p/22253

 

This question may be simple to a lot of people. I am fairly new to scripting and I really appreciate your help.

I have a .json file automatically getting created in a folder after the user make a selection on the web( lot number, wafer number, parameter). I want to run a background script which automatically takes that .json and it needs to access set of folders to compute the trend. Like whenever a .json file is created in that folder, script should run to compute.

 

Is there a way to append 

include("$downloads/JSON Parser II.jsl");
JSON:MAKETABLE(source);

to the starting and beginning of a json script without opening the .json file? Am I in the right path or should I use .json file to implement in a different way?

 

Thank you.

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: .json file to trend charts

In JMP 13, there are built-in JSON Parsing functions. The JSON to List, Load Text File, and Open functions support the JSON file type.

If you just want to convert a JSON file to a JMP Data Table, you can use the Open function with the JSON option.

dt = Open(  "$documents\test.json", JSON );

Edit:  The Open function should do the same as the JSON:MAKETABLE function from the JSON utilities. 

Justin

View solution in original post

Craige_Hales
Super User

Re: .json file to trend charts

Edit: too much going on...all the XML references below should be json instead...

 

The original question also asked about using a folder name from the XML data. That folder contains a CSV file with the actual data. The folder name is in a column with a name like Infoes.Name. The dotted name represents a nested path in the XML tree. You can use that to open a file in the folder.

I recommend using the text import peview to create a source script that you can copy from the imported table. The script will look something like this (use right-click->edit  on source to get a copy):

Text import preview source scriptText import preview source script

 

Open(
    "C:\Users\v1\Desktop\stories.csv",
    columns(
        ...
    ),
    Import Settings(
        ...
    )
)

You can replace the quoted filename on the second line with a JSL variable that contains the name of the file you actually need. I don't know if your XML file contains only one file or more than one; you might use something like this to process all of them.

 

 

For( irow = 1, irow <= N Rows( dtXML ), irow++,
filename = dtXML:Infoes.Name[irow] || "\data.csv";
show(filename); // check the log to see if this looks right
dtCSV = Open( filename, columns(...), Import Settings(...) );
// do something with the data
// ... maybe dtCSV<<Distribution(...) for example
// then close the table...
Close( dtCSV, "nosave" );
)

You'll need to think about the \ in the path name which I just stuck in front of the hard-coded data.csv name, and you might need to get the actual file name from another variable. Since there is more than one data table open, be sure to use distinctive JSL variable names to prevent confusion, and be sure to use the JSL variable name to avoid using the current data table, since it will not be obvious what table is current.

 

Craige

View solution in original post

4 REPLIES 4
Craige_Hales
Super User

Re: .json file to trend charts

use the LoadTextFile function to open the json file and store it into source.

source = LoadTextFile("$desktop/x.json");
Craige

Re: .json file to trend charts

In JMP 13, there are built-in JSON Parsing functions. The JSON to List, Load Text File, and Open functions support the JSON file type.

If you just want to convert a JSON file to a JMP Data Table, you can use the Open function with the JSON option.

dt = Open(  "$documents\test.json", JSON );

Edit:  The Open function should do the same as the JSON:MAKETABLE function from the JSON utilities. 

Justin
Craige_Hales
Super User

Re: .json file to trend charts

Didn't realize that made it into 13, cool!

Craige
Craige_Hales
Super User

Re: .json file to trend charts

Edit: too much going on...all the XML references below should be json instead...

 

The original question also asked about using a folder name from the XML data. That folder contains a CSV file with the actual data. The folder name is in a column with a name like Infoes.Name. The dotted name represents a nested path in the XML tree. You can use that to open a file in the folder.

I recommend using the text import peview to create a source script that you can copy from the imported table. The script will look something like this (use right-click->edit  on source to get a copy):

Text import preview source scriptText import preview source script

 

Open(
    "C:\Users\v1\Desktop\stories.csv",
    columns(
        ...
    ),
    Import Settings(
        ...
    )
)

You can replace the quoted filename on the second line with a JSL variable that contains the name of the file you actually need. I don't know if your XML file contains only one file or more than one; you might use something like this to process all of them.

 

 

For( irow = 1, irow <= N Rows( dtXML ), irow++,
filename = dtXML:Infoes.Name[irow] || "\data.csv";
show(filename); // check the log to see if this looks right
dtCSV = Open( filename, columns(...), Import Settings(...) );
// do something with the data
// ... maybe dtCSV<<Distribution(...) for example
// then close the table...
Close( dtCSV, "nosave" );
)

You'll need to think about the \ in the path name which I just stuck in front of the hard-coded data.csv name, and you might need to get the actual file name from another variable. Since there is more than one data table open, be sure to use distinctive JSL variable names to prevent confusion, and be sure to use the JSL variable name to avoid using the current data table, since it will not be obvious what table is current.

 

Craige