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.

Getting ready

In order to perform this recipe, we will require the following:

  1. 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 ...

  1. As we will be reading or parsing a JSON file, first, we will be creating a JSON parser:
            JSONParser parser = new JSONParser(); 
    
  2. Then, in a try block, 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 ...

Get Java Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.