BookmarkSubscribe
Choose Language Hide Translation Bar
Highlighted
uday_guntupalli
Community Trekker

Efficient Construction of XML and JSON

All, 

   Looking for guidance on encoding data into XML as well as JSON from JMP (just to narrow the scope - associative arrays). The following discussion had some relevant to JSON construction, but i was running into some errors with the function posted and also did not see if a solution was acheived. This can be acheived reasonably by using either R ( toJSON function) or Python. Wondering how this can be done in JSL. 
    https://community.jmp.com/t5/Discussions/Define-JSON-structure-for-data-exchange-which-supports-tabl...

Best
Uday
0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Efficient Construction of XML and JSON

Not all is lost! :)

As JSON Expr was introduced in 13.0 so you have it. You won't have Parse JSON and JSON boolean constants, though, and Associative Array construction is not as streamlined as in the example above. I just tested the following in 13.1:

 

 

Names Default To Here( 1 );
aa = [
"a" => 1,
"b" => "B",
"c" => 1
];
aa["d"] = ["d1" => 1, "d2" => 2];
aa["e"] = {1, 2};
// JSL to JSON string
json = As JSON Expr( aa );
Show(json);

The result is:

json = "{\!"a\!":1,\!"b\!":\!"B\!",\!"c\!":1,\!"d\!":{\!"d1\!":1,\!"d2\!":2},\!"e\!":[1,2]}
";

 

 

0 Kudos
5 REPLIES 5

Re: Efficient Construction of XML and JSON

How about using As JSON Expr()? You can give it your associative array and it should take care of the rest.

Names Default To Here( 1 );
aa = [
	"a" => 1,
	"b" => "B",
	"c" => true,
	"d" => [ "d1" => 1, "d2" => 2],
	"e" => { 1, 2, 3}
];
// JSL to JSON string
json = As JSON Expr( aa );
Show(json);
// JSON string back to JSL
aa2 = Parse JSON (json);
// check if they match
Show(char(aa) == char(aa2));

The result should be (tested in 14.0):

json = "{\!"a\!":1,\!"b\!":\!"B\!",\!"c\!":\!"true\!",\!"d\!":{\!"d1\!":1,\!"d2\!":2},\!"e\!":[1,2,3]}";
Char(aa) == Char(aa2) = 1;
uday_guntupalli
Community Trekker

Re: Efficient Construction of XML and JSON

@nascif_jmp,
        I only have JMP 13.1.0 at this point. But will make a note. Thank you.

Best
Uday
0 Kudos

Re: Efficient Construction of XML and JSON

Not all is lost! :)

As JSON Expr was introduced in 13.0 so you have it. You won't have Parse JSON and JSON boolean constants, though, and Associative Array construction is not as streamlined as in the example above. I just tested the following in 13.1:

 

 

Names Default To Here( 1 );
aa = [
"a" => 1,
"b" => "B",
"c" => 1
];
aa["d"] = ["d1" => 1, "d2" => 2];
aa["e"] = {1, 2};
// JSL to JSON string
json = As JSON Expr( aa );
Show(json);

The result is:

json = "{\!"a\!":1,\!"b\!":\!"B\!",\!"c\!":1,\!"d\!":{\!"d1\!":1,\!"d2\!":2},\!"e\!":[1,2]}
";

 

 

0 Kudos
BioData41
Community Trekker

Re: Efficient Construction of XML and JSON

When I run this in JMP 13.0, I get the following output in the log window:

json = "{\!"unsupported\!":\!"\!"}
";

Any idea what might be wrong? 

 

Names Default To Here( 1 );
aa = [
"a" => 1,
"b" => "B",
"c" => 1
];
aa["d"] = ["d1" => 1, "d2" => 2];
aa["e"] = {1, 2};
json = As JSON Expr(aa);
Show(json);

 

0 Kudos
uday_guntupalli
Community Trekker

Re: Efficient Construction of XML and JSON

@BioData41
        I tested your code in JMP 14 and JMP 13.1.0 and it worked fine. Sorry I don't have access to JMP 13.0 

Best
Uday