O'Reilly logo

Advanced Java® EE Development with WildFly® by Deepak Vohra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required