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

Write JSON data

From the course: JSON Processing with Java EE

Start my 1-month free trial

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…

Contents