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]]
Sent: Wednesday, April 13, 2016 2:13 PM
To: [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] 
with "unsubscribe terascript-talk" in the body.

Attachment: json_parser.tml
Description: Binary data

Reply via email to