You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Richard Salz <rs...@us.ibm.com> on 2011/02/05 00:21:19 UTC
Encoding json
So, how would you encode json, assuming no limits on nesting depth?
Right now I'm thinking of "flattening" the structure, where you get the
full name as list<string>, and the value as a string, which is either a
simple value or empty, and you look for children to get the value of the
aggregate.
Any thoughts?
/r$
--
STSM, WebSphere Appliance Architect
https://www.ibm.com/developerworks/mydeveloperworks/blogs/soma/
Re: Encoding json
Posted by Richard Salz <rs...@us.ibm.com>.
Joe Pepersack <jo...@pepersack.net> wrote on 02/05/2011 09:13:03 AM:
> manner. See http://search.cpan.org/~makamaka/JSON-2.50/lib/JSON.pm
> however. See: http://www.json.org/javadoc/org/json/JSONStringer.html
I guess I wasn't clear. It's not about other languages, it's about how
you'd do it in thrift IDL.
/r$
--
STSM, WebSphere Appliance Architect
https://www.ibm.com/developerworks/mydeveloperworks/blogs/soma/
Re: Encoding json
Posted by Joe Pepersack <jo...@pepersack.net>.
In Perl, it's trivial. The JSON module from CPAN will round-trip any
arbitrary structure of any depth into a JSON string in a very efficient
manner. See http://search.cpan.org/~makamaka/JSON-2.50/lib/JSON.pm
use JSON;
$encoder = JSON->new();
$json_string = JSON->encode( $complex_structure );
$new_struct = JSON->decode( $json_string );
For Java, it appears that JSONStringer provides similar functionality
although it's limited to 20 levels. I haven't personally used it,
however. See: http://www.json.org/javadoc/org/json/JSONStringer.html
You can embed Perl inside a Java program using PLJava -
http://search.cpan.org/~gmpassos/PLJava-0.04/README.pod
You can embed Java inside a Perl program using Inline::Java -
http://search.cpan.org/~patl/Inline-Java-0.53/Java.pod
On 02/04/2011 06:21 PM, Richard Salz wrote:
> So, how would you encode json, assuming no limits on nesting depth?
>
> Right now I'm thinking of "flattening" the structure, where you get the
> full name as list<string>, and the value as a string, which is either a
> simple value or empty, and you look for children to get the value of the
> aggregate.
>
> Any thoughts?
>
> /r$
>
> --
> STSM, WebSphere Appliance Architect
> https://www.ibm.com/developerworks/mydeveloperworks/blogs/soma/
>