Thanks for your code ☺ Very helpful.
I did get the following to work, although it assumes I already know the JSON
part names – and isn’t creating the full array:
<@assign request$test_json value='{"name":"Johnson, John","street":"Oslo West
16","phone":"555 1234567"}'>
<@assign request$jname <@script>JSON.parse('<@var
request$test_json>').name;</@script>>
<@assign request$jphone <@script>JSON.parse('<@var
request$test_json>').phone;</@script>>
From: Robert Shubert [mailto:[email protected]]
Sent: Thursday, April 14, 2016 8:22 AM
To: [email protected]
Subject: RE: TeraScript-Talk: Best way to parse JSON objects
That action/tag does still exist. However, due to changes in v7 (notably being
64-bit) the engine was changed. JS wasn’t working at all in 7.0.1. In 7.0.3 we
fixed the tag but left the action disabled on 64-bit Windows. The tag no longer
interacts with the server object either, so the response of of the JS tag would
need to be TML that could be executed to create the array. I believe the JS
execution would be faster than the code I posted yesterday, but be somewhat
more awkward to implement.
All of this will be sorted out and imporved in v8.
Robert
From: Anthony Humphreys [mailto:[email protected]]
Sent: Thursday, April 14, 2016 2:24 AM
To: [email protected]<mailto:[email protected]>
Subject: RE: TeraScript-Talk: Best way to parse JSON objects
Back in the day, I'd use the built-in JS action, and use JSON2.JS to parse JSON
objects, and then pass back to Tango what I needed with the sever object's set
variable.
Does TeraScript still have a JS action or JS tag?
On Apr 13, 2016 19:25, "Robert Shubert"
<[email protected]<mailto:[email protected]>> wrote:
Dave,
TS 7 doesn’t have a JSON parser built-in. It’s something we can support in 8
because we have nested collections.
I whipped up a simple JSON parser, which is attached. It’s just a block of TML
that you can adapt. It’s not very powerful and won’t support nested objects
(because TS 7 wouldn’t allow that easily) and won’t handle arrays (just not
supported)
It does handle quoting, as in your example, as well as \-escaped characters and
numbers. Note that it does not handle the \uXXXX hex encoding either.
Let me know if you have any questions. Or need help improving the code. Or find
a bug.
Oh, it also won’t be very fast, so large strings will take time.
I left your test string (with some additions) in the file so you can see it
work. It will also attempt to realize when the parsing failed and throw an
error – although this is very simple right now.
Robert
From: Dave Machin
[mailto:[email protected]<mailto:[email protected]>]
Sent: Wednesday, April 13, 2016 2:13 PM
To: [email protected]<mailto:[email protected]>
Subject: TeraScript-Talk: Best way to parse JSON objects
I’m trying to figure out the most efficient way to parse JSON objects and can’t
seem to think of a simple method.
The <@tokenize> tag seems to get me close but doesn’t fully work.
For example,
If I have this JSON data, where there is a comma in the “name” value:
<@assign request$test_json value='{"name":"Johnson, John","street":"Oslo West
16","phone":"555 1234567"}'>
And I then do this:
<@tokenize value=<@var request$test_json> CDELIM=":" RDELIM=",">
I end up with this:
{"name"
"Johnson
John"
"street"
"Oslo West 16"
"phone"
"555 1234567"}
So the comma in their name is causing trouble.
Is there some kind of best-practice way of parsing JSON data with WiTango?
We’re on version 7.0.7 currently.
Thanks
Dave Machin
________________________________
To unsubscribe from this list, please send an email to
[email protected]<mailto:[email protected]> with "unsubscribe
terascript-talk" in the body.
________________________________
To unsubscribe from this list, please send an email to
[email protected]<mailto:[email protected]> with "unsubscribe
terascript-talk" in the body.
________________________________
To unsubscribe from this list, please send an email to
[email protected]<mailto:[email protected]> with "unsubscribe
terascript-talk" in the body.
________________________________
To unsubscribe from this list, please send an email to
[email protected]<mailto:[email protected]> with "unsubscribe
terascript-talk" in the body.
Email Confidentiality Notice: The information contained in this transmission is
confidential, proprietary or privileged and may be subject to protection under
the law. The message is intended for the sole use of the individual or entity
to whom it is addressed. If you are not the intended recipient, you are
notified that any use, distribution or copying of the message is strictly
prohibited and may subject you to criminal or civil penalties. If you received
this transmission in error, please contact the sender immediately by replying
to this email and delete the material from any computer.
----------------------------------------
To unsubscribe from this list, please send an email to [email protected]
with "unsubscribe terascript-talk" in the body.