Java – read JSON file – Multiple Records

#ReadJSON #JavaReadJSON #JavaReadMultipleRecordsJSON

Java – read a JSON file – Multiple Records

Like, Share, And Subscribe | Professor Saad Yousuf
Watch Our All Videos On This :
Subscribe Our Channel :

JSON Jar File Link:

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 {

public static void main(String[] args) {
JSONParser jsonP = new JSONParser();

try(FileReader reader = new FileReader(“emps.json”)){
//Read JSON File
Object obj = jsonP.parse(reader);
JSONArray empList = (JSONArray) obj;
//Iterate over emp array
empList.forEach(emp -> parseEmpObj((JSONObject)emp));
catch (FileNotFoundException e) {
} catch (IOException e) {
} catch (ParseException e) {
private static void parseEmpObj(JSONObject emp) {
JSONObject empObj = (JSONObject) emp.get(“employee”);
//get emp firstname, lastname, website
String fname = (String) empObj.get(“firstname”);
String lname = (String) empObj.get(“lastname”);
String website = (String) empObj.get(“website”);
System.out.println(“First Name: ” + fname);
System.out.println(“Last Name: ” + lname);
System.out.println(“Website: ” + website);


Xem thêm bài viết khác:

Article Categories:
Công Nghệ


  • How can i access a json object inside a json object?

    likitha guntha July 1, 2020 1:58 pm Reply
  • Hello sir…i am getting error..Unexpected character () at position 0.

    Please help

    Pranta Pratim Roy July 1, 2020 1:58 pm Reply
  • Hello. You tutorial on dom parser for reading XML was very informative. Please also do a tutorial on creating an XML(with nested nodes)using another XML as input with dom parser in Java. Thanks in advance.

    faisal jamal July 1, 2020 1:58 pm Reply

Leave a Reply

Your email address will not be published. Required fields are marked *