In the spirit of creating simple, copyable Java based JSON examples, here are some JSON Array and JSON Object processing samples. To keep it super easy to read, there is no database access or any other logic to clutter up the simple use cases presented here.
These examples are using the json-simple api that is common in many Java implementations.
Get the json-simple jar:
download json-simple-1.1.1.jar
Get the source for json-simple on github: download json-simple source
Check out the Google archive for more info on json-simple here: Read about it on Google
If you would like the eclipse project that contains the code below:
download java-json-simple eclipse project
Check out json.org for a long list of JSON parsers across many different languages.
This example creates a simple, single record style JSON Object.
This example creates an outer JSON object for “root” containing a JSON Array which contains 2 record style JSON Objects.
This example creates an outer JSON object for “root” containing a JSON Array which contains 2 record style JSON Objects. Each of the record style JSON Objects contains a JSON Array.