|Guillaume Laforge||Jan 28, 2011 8:25 am|
|Alex Tkachman||Jan 28, 2011 8:39 am|
|Guillaume Laforge||Jan 28, 2011 8:43 am|
|Cédric CHAMPEAU||Jan 28, 2011 8:49 am|
|Guillaume Laforge||Jan 28, 2011 8:57 am|
|Merlyn Albery||Jan 28, 2011 9:22 am|
|Thom Nichols||Jan 28, 2011 11:20 am|
|Jochen Theodorou||Jan 28, 2011 11:52 am|
|Thom Nichols||Jan 28, 2011 12:48 pm|
|Guillaume Laforge||Jan 28, 2011 2:56 pm|
|Guillaume Laforge||Jan 28, 2011 3:05 pm|
|Jochen Theodorou||Jan 29, 2011 12:00 am|
|Thom Nichols||Jan 29, 2011 10:42 am|
|Guillaume Laforge||Jan 29, 2011 12:29 pm|
|Paulo Gabriel Poiati||Jan 29, 2011 2:03 pm|
|Guillaume Laforge||Jan 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|
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.
-- Guillaume Laforge Groovy Project Manager Head of Groovy Development at SpringSource http://www.springsource.com/g2one