atom feed16 messages in org.codehaus.groovy.dev[groovy-dev] Built-in JSON support in...
FromSent OnAttachments
Guillaume LaforgeJan 28, 2011 8:25 am 
Alex TkachmanJan 28, 2011 8:39 am 
Guillaume LaforgeJan 28, 2011 8:43 am 
Cédric CHAMPEAUJan 28, 2011 8:49 am 
Guillaume LaforgeJan 28, 2011 8:57 am 
Merlyn AlberyJan 28, 2011 9:22 am 
Thom NicholsJan 28, 2011 11:20 am 
Jochen TheodorouJan 28, 2011 11:52 am 
Thom NicholsJan 28, 2011 12:48 pm 
Guillaume LaforgeJan 28, 2011 2:56 pm 
Guillaume LaforgeJan 28, 2011 3:05 pm 
Jochen TheodorouJan 29, 2011 12:00 am 
Thom NicholsJan 29, 2011 10:42 am 
Guillaume LaforgeJan 29, 2011 12:29 pm 
Paulo Gabriel PoiatiJan 29, 2011 2:03 pm 
Guillaume LaforgeJan 29, 2011 2:12 pm 
Subject:[groovy-dev] Built-in JSON support in 1.8
From:Guillaume Laforge (glaf@gmail.com)
Date:Jan 28, 2011 8:25:32 am
List:org.codehaus.groovy.dev

Hi all,

As part of the Groovy 1.8 roadmap, we had an item for *supporting JSON* in Groovy, similarily as to how we support XML, namely by providing a parser (slurper) and a builder. I've implemented a Groovy *JsonSlurper* and *JsonParser*, in the * groovy.json* package. It's currently in Trunk.

You can play with those parser and builder by using a snapshot of Groovy 1.8 that you can find on Bamboo, for example: http://bamboo.ci.codehaus.org/browse/GROOVY-CORE-5493/artifact/deliverables

You can have a look at the *JSON GEP* that Andres and I started a few months ago (GEP-7): http://docs.codehaus.org/display/GroovyJSR/GEP+7+-+JSON+Support It shows some of the examples.

But you can have a better overview of the various possibilities by looking at the test cases here: http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/test/groovy/json/ In particular the builder tests: http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/test/groovy/json/JsonBuilderTest.groovy And the parser tests: http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/test/groovy/json/JsonSlurperTest.groovy http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/test/groovy/json/RealJsonPayloadsTest.groovy

And you can have a look at the sources too: http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/main/groovy/json/ <http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/main/groovy/json/>Be sure to look at the JavaDocs which show various examples as well.

Although JSON and XML are pretty different, it would be nice if xml builders and json builder would be even closer (which is one of the goals of the built-in JSON support), as for example the following cases are not covered by the current implementation: http://docs.codehaus.org/display/GroovyJSR/GEP+7+-+JSON+Support#GEP7-JSONSupport-Openquestions I'd be interested in your input as how you'd expect such calls on the builder should serialize the JSON output, or even if we should even support them at all.

Thanks for your attention.