From the course: JSON Processing with Java EE

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: JSON array object

Solution: JSON array object

From the course: JSON Processing with Java EE

Start my 1-month free trial

Solution: JSON array object

- [Instructor] So, how did you find your first challenge? Well, that challenge had two parts. Write code that loads a file containing a JSON and array and parse it into an object. And secondly, to write an appropriate unit test. So, let's start with the code part. As you can see here, the code is very similar to the code we wrote in the load JSON object method. The only difference is the method we call on the read object. This method reads the JSON data as JSON array, rather than as JSON object. It is important to note that if the data in the file is not actually a JSON array, the parse will not be able to read it and will throw a JSON parsing exception. So, you have to be sure of the data format if you wish to use this method. Alternatively, if you're not sure of the data structure, you could use the read method. This method returns a JSON structure, which represents all JSON structures. And then use the get value type to determine its type. To see an example of this, take a look at…

Contents