Oct 02
Sprague, Gary Another Approach to Decoding JSON?
Oct 02, 2014; 23:24
Sprague, Gary
Another Approach to Decoding JSON?
Hi all.
Just wanted to share some work that I've done to speed up the JSON decoding. I have a work need to decode JSON data and found the Lasso 8.6 decoding a bit slow.
I know that James Harvard was working on improving JSON encoding, but didn't hear much about the decoding end.
Anyway, I need to decode several JSON objects hourly and found the particular payload running about 5 seconds per decode. I was able to shorten that to 265ms with the following approach.
define_tag('DecodeJSON',
-required = 'JSON');
local('_return'='');
if(#JSON != '');
#JSON->replace(regexp(-find='([^\\\\]{1})\'',-replace='\\1\\\\\''));
#JSON->replace(regexp(-find='([^\\\\]{1}\")\\s*:',-replace='\\1='<smb://s*:',-replace='//1='>));
#JSON->replace(regexp(-find='([^\\\\]{1})""',-replace='\\1\'\'')); //Here we replace empty strings in quotes
#JSON->replace(regexp(-find='([^\\\\]{1})"',-replace='\\1\'')); //Here replace individual quotes around strings
#JSON->replace(regexp(-find='(^|[^\\\\]{1})\\{',-replace='\\1map('));
#JSON->replace(regexp(-find='(^|[^\\\\]{1})\\[',-replace='\\1array('))<smb://[',-replace='//1array('))>;
#JSON->replace(regexp(-find='([^\\\\]{1})\\]',-replace='\\1<smb://]',-replace='//1>)'));
#JSON->replace(regexp(-find='([^\\\\]{1})\\}',-replace='\\1)'));
process('[local(\'_return\' = ' + #JSON + ')]');
/if;
return(#_return);
/define_tag;
I expect peer review will point out that I'm not cleaning up date formats or handling UTF-16 or UTF-32 nor is there any error handling here, but it does work pretty fast.
Given that the JSON objects and arrays are basically Lasso maps and arrays, with slightly different syntax, regular expression replaces seemed natural.
I used the RFC on the subject to guide: http://www.ietf.org/rfc/rfc4627.txt?number=4627
Feedback welcome!
Gary Sprague
TV Systems Engineer
HSN, 1 HSN Drive, St. Petersburg, FL 33729
Office 727.872.4489
Gary.Sprague@hsn.net<mailto:Gary.Sprague@hsn.net>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Oct 02
Steve Piercy - Website Builder Re: Another Approach to Decoding JSON?
Oct 02, 2014; 17:21
Steve Piercy - Website Builder
Re: Another Approach to Decoding JSON?
Oct 03
Sprague, Gary Re: Another Approach to Decoding JSON?
Oct 03, 2014; 10:30
Sprague, Gary
Re: Another Approach to Decoding JSON?
Oct 03
Jolle Carlestam Re: Another Approach to Decoding JSON?
Oct 03, 2014; 13:24
Jolle Carlestam
Re: Another Approach to Decoding JSON?
Oct 03
Kyle Jessup Re: Another Approach to Decoding JSON?
Oct 03, 2014; 10:16
Kyle Jessup
Re: Another Approach to Decoding JSON?
Oct 03
Sprague, Gary Re: Another Approach to Decoding JSON?
Oct 03, 2014; 14:55
Sprague, Gary
Re: Another Approach to Decoding JSON?
Oct 03
Steve Piercy - Website Builder Re: Another Approach to Decoding JSON?
Oct 03, 2014; 14:05
Steve Piercy - Website Builder
Re: Another Approach to Decoding JSON?
Oct 07
Sprague, Gary Re: Another Approach to Decoding JSON?
Oct 07, 2014; 16:13
Sprague, Gary
Re: Another Approach to Decoding JSON?
Oct 07
Steve Piercy - Website Builder Re: Another Approach to Decoding JSON?
Oct 07, 2014; 13:18
Steve Piercy - Website Builder
Re: Another Approach to Decoding JSON?