Reading JSON files using JSON.simple
In this recipe, we will see how we can read or parse a JSON file. As our sample input file, we will be using the JSON file we created in the previous recipe.
In order to perform this recipe, we will require the following:
- Use the previous recipe to create a JSON file with book, author, and reviewer comments information. This file will be used as an input for parsing/reading in this recipe.
How to do it ...
- As we will be reading or parsing a JSON file, first, we will be creating a JSON parser:
JSONParser parser = new JSONParser();
- Then, in a
tryblock, we will be retrieving the values in the fields book and author. However, to do that, we first use the
parse()method of the parser to read the input ...