out.println("<title>Create JSON structures</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Generate JSON using JsonGeneratorFactory</h1>");
// JsonGeneratorFactory factory = Json.createGeneratorFactory(new JsonConfiguration().withPrettyPrinting());
JsonGeneratorFactory factory = Json.createGeneratorFactory(null);
// JsonGenerator gen = factory.createGenerator(System.out);
out.println("Creating an empty object ...<br>");
JsonGenerator gen = factory.createGenerator(out);
// JsonGenerator gen = Json.createGenerator(out);
gen.writeStartObject().writeEnd();
gen.flush();
out.println("<br>...done<br>");
out.println("<br>Creating a simple object ...<br>");
gen = factory.createGenerator(out);
gen
.writeStartObject()
.write("apple", "red")
.write("banana", "yellow")
.writeEnd();
gen.flush();
out.println("<br>...done<br>");
out.println("<br>Creating a simple array ...<br>");
gen = factory.createGenerator(out);
gen
.writeStartArray()
.writeStartObject()
.write("apple", "red")
.writeEnd()
.writeStartObject()
.write("banana", "yellow")
.writeEnd()
.writeEnd();
gen.flush();
out.println("<br>...done<br>");
out.println("<br>Creating a nested structure ...<br>");
gen = factory.createGenerator(out);
gen
.writeStartObject()
.write("title", "The Matrix")
.write("year", 1999)
.writeStartArray("cast")