From the course: JSON Processing with Java EE
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Write JSON data
- [Instructor] Okay, so we're going to generate a string of JSON data, just as we did with the object model. And by using the same JSON data. If you want to follow along with this example, open up the streaming example three class file from the exercise folder. As before, we're going to use a string writer. This makes it easy to test, but you can use any writer or output stream instance, depending on the requirements. Now, because there is a lot of JSON data to write, I'm going to copy and paste a code from a file in the exercise files associated with this lesson. I'm going to copy the entire write JSON stream to string method. So firstly, we start the construction of the JSON object by calling the write start object on the generator instance. Then, we call the write method for as many times as there are elements in the object. If an element is an array, we call the write start array method. And we continue calling write for each element in the array until the end. When we called…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Introduction to the streaming model2m 43s
-
(Locked)
Parse JSON data6m 47s
-
(Locked)
Write JSON data2m 3s
-
(Locked)
Challenge: Find the value of a JSON key34s
-
(Locked)
Solution: Find the value of a JSON key32s
-
(Locked)
Challenge: Output JSON object to a file22s
-
(Locked)
Solution: Output JSON object to file13s
-
(Locked)
-