I have the following string from a REST JSON response:
[
{
"uid":10512213,
"name":"Bob"
},
{
"uid":7208201,
"name":"John"
},
{
"uid":10570,
"name":"Jim"
},
{
"uid":1799657,
"name":"Sally"
}
]
The rest response definition is from Facebook: FB REST Link
I am using Google App Engine + GAELYK which runs in Jetty.
What is the best way to convert the above into array of maps in Groovy on the Server. (This would probably have to recurse through the response)
I am looking for something easy that doesn’t include a lot of libraries. (I dont have maven)
EDIT: Groovy since 1.8.0 has an integrated JsonSlurper:
Old answer below:
Use JsonSlurper…
An example script to read that response would be:
This outputs:
As you can see,
listis a list of Maps, so if you just wanted a list of the names for example, you could just do:To use this in your Gaelyk app, you should just need to download json-lib-2.3-jdk15.jar from here and do something similar (without the @Grab then, as you’ll have the jar in your
WEB-INF/libfolder.–edit–
Looking around, found this page showing the dependencies for json-lib
The @Grab in the test script does a lot of background work for you