Creating JSON

In this section, we will create a Java object model for JSON and output the JSON to a file. We will use the Java API for JSON processing to create the following JSON structure in createJson.jsp:

{
"journal":"Oracle Magazine",
"edition":
{"date":"March April 2013","cover":"Public Cloud. Private Cloud"},
"catalog":
[
{"title":"PaaS Fits the Enterprise","author":"David Baum"},
{"title":"On Becoming Others, Limits, and Restoration","author":"Tom Kyte"}
]
}

A JSON Java object model is represented by the JsonObject class. The JsonObjectBuilder interface can be used to initialize a JSON object model and create a JSON object. First, create a JsonObjectBuilder object using createObjectBuilder(), the Json class static method, as follows:

JsonObjectBuilder ...

Get Advanced Java® EE Development with WildFly® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.