how to read from json files in java

package com.howtodoinjava.demo.jsonsimple;
 
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
 
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
 
public class ReadJSONExample 
{
    @SuppressWarnings("unchecked")
    public static void main(String[] args) 
    {
        //JSON parser object to parse read file
        JSONParser jsonParser = new JSONParser();
         
        try (FileReader reader = new FileReader("employees.json"))
        {
            //Read JSON file
            Object obj = jsonParser.parse(reader);
 
            JSONArray employeeList = (JSONArray) obj;
            System.out.println(employeeList);
             
            //Iterate over employee array
            employeeList.forEach( emp -> parseEmployeeObject( (JSONObject) emp ) );
 
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
 
    private static void parseEmployeeObject(JSONObject employee) 
    {
        //Get employee object within list
        JSONObject employeeObject = (JSONObject) employee.get("employee");
         
        //Get employee first name
        String firstName = (String) employeeObject.get("firstName");    
        System.out.println(firstName);
         
        //Get employee last name
        String lastName = (String) employeeObject.get("lastName");  
        System.out.println(lastName);
         
        //Get employee website name
        String website = (String) employeeObject.get("website");    
        System.out.println(website);
    }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
read json file as string java reading a json in java read json file in json object java reading a json file in java load json java file load json java fil read json file java java org.json from file read json file on java read json file java standard java read load jsonl file how to read a json file in java with objects how to make java read json file how to access json objects from a file in java how to read a json in java how to access json from file java how to read json object from file in java read json file with jsonobject java how to read a json from the file java a read json file and load to object in java how to read json string from a file in java read .json file java how to read json from file in java java read in json file read json objects from text file java read json objects from txt file java read text file as json java read txt json java java json read from file read json string from file java how to read a field value from json file in java java json file read .json file in java read file json java read a jason file in java read data from json file in java java how to read json file java read json file to string read json file java 8 How to extract data from JSON file in Java how to read json with java How to get JSON data from json file in java java read file to jsonobject convert json read from file in java read json from file java java read json from file and convert to java object in java read json file in java to string read json in java read data from a json file in java simply read data from a json file in java how to read data from json file in java read from json in java hwo to read java resouce json file into Json read json file file in java and parse it java read json from file how to read from a json file java how to read fro json java read json file in java gjoson how to read json file as string in java how to read json data in java java code to read json file read string from json file java read json object from file in java how read json file in java how to read json data from text file in java reading json file in java read json file from url java how to read in json file java how to read json from local file in java how to read a json file in java how te read a .json fie in java load json file java how to extract data from a json file in java get json file as json string java java library to read json file java json simple read file read json file java read json file in java how to read json file into an object javafile json file in java Read Json from file java read json file into json object java java json files org json java get object from file read from json file java java get data from json file load json file into object java read json from a file in java to map read json from a file in java load json file with java java read json file how to read json file in java how to load json file in java reading json file without using simple in java reading json file without json library in java how to read json file in java without library getting information from json files in Java load data from json file java reading json files in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source