thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Pepersack <...@pepersack.net>
Subject Re: Encoding json
Date Sat, 05 Feb 2011 14:13:03 GMT
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/
>

Mime
View raw message