java load json file

Solutions on MaxInterview for java load json file by the best coders in the world

showing results for - "java load json file"
Laura
12 Aug 2016
1import net.sf.json.JSONObject;
2import net.sf.json.JSONSerializer;
3import org.apache.commons.io.IOUtils; 
4
5    public class JsonParsing {
6
7        public static void main(String[] args) throws Exception {
8            InputStream is = 
9                    JsonParsing.class.getResourceAsStream( "sample-json.txt");
10            String jsonTxt = IOUtils.toString( is );
11
12            JSONObject json = (JSONObject) JSONSerializer.toJSON( jsonTxt );        
13            double coolness = json.getDouble( "coolness" );
14            int altitude = json.getInt( "altitude" );
15            JSONObject pilot = json.getJSONObject("pilot");
16            String firstName = pilot.getString("firstName");
17            String lastName = pilot.getString("lastName");
18
19            System.out.println( "Coolness: " + coolness );
20            System.out.println( "Altitude: " + altitude );
21            System.out.println( "Pilot: " + lastName );
22        }
23    }
24
Roberto
15 Apr 2020
1package com.howtodoinjava.demo.jsonsimple;
2 
3import java.io.FileWriter;
4import java.io.IOException;
5 
6import org.json.simple.JSONArray;
7import org.json.simple.JSONObject;
8 
9public class WriteJSONExample
10{
11    @SuppressWarnings("unchecked")
12    public static void main( String[] args )
13    {
14        //First Employee
15        JSONObject employeeDetails = new JSONObject();
16        employeeDetails.put("firstName", "Lokesh");
17        employeeDetails.put("lastName", "Gupta");
18        employeeDetails.put("website", "howtodoinjava.com");
19         
20        JSONObject employeeObject = new JSONObject(); 
21        employeeObject.put("employee", employeeDetails);
22         
23        //Second Employee
24        JSONObject employeeDetails2 = new JSONObject();
25        employeeDetails2.put("firstName", "Brian");
26        employeeDetails2.put("lastName", "Schultz");
27        employeeDetails2.put("website", "example.com");
28         
29        JSONObject employeeObject2 = new JSONObject(); 
30        employeeObject2.put("employee", employeeDetails2);
31         
32        //Add employees to list
33        JSONArray employeeList = new JSONArray();
34        employeeList.add(employeeObject);
35        employeeList.add(employeeObject2);
36         
37        //Write JSON file
38        try (FileWriter file = new FileWriter("employees.json")) {
39 
40            file.write(employeeList.toJSONString());
41            file.flush();
42 
43        } catch (IOException e) {
44            e.printStackTrace();
45        }
46    }
47}
48
queries leading to this page
how to read a json file in java with objectsread json file into json object javahow to read json file using javajava read in json filejson in java json from fileread a json file and convert to java objectjava read load jsonl filejava read and load json filejava get json from filehow to read a json file javahow to read json in javajava read jsonjava read json filesload json object java from filejson java read from fileload json from filejava read json filereading json file without domain in spring boothow to read json file in javaloading json file in javareading json file without json library in javaget json from file javafile json javaread json file java standardjava decode jsonhow to read json files in javaread json from a file javaread a json file javahow to read in json file javaload json file into object javacan you use readfile for json files in javahow to read a json file in a package in javajava working with json fileread json file javajava read from json filejava open big json fileload data from json file javareading json files in javaread json file java 8how to read json object from file in javahow to use a json file in javajson files with javaread json object from file in javaopen json file javajava get info from json fileread json file and java objectsjava read a json fileread file content java jsonread local json file in java without librarycreate json object from file javajava how to open and read json filewriting gson to file jaaread json from file javajava read in json from fileread json file as object javajsonobject read javajava json file java read write list from jsonjava read json file without libraryread json file to json object javaload json file as scriptread json from file java using org jsonjava json how to open and read json fileread json file in javaread object from json file javahow to load json file with javaload json java fileread json fle in javareading from a json file javaparse json from file javagjson read objects javahow to read json object from text file in javahow to save and load json file in windowsorg json read json file javaparsing a json file in javahow to read a json file in javaorg json jsonobject from file javaread json from file java javacreate json object from json file javaload json java filimport json file to object javahow to read a jason object from jason filehow to parse and load json files in javaload json file with javascriptjava library to read json fileread json file as json object javajava load load json from fileparse json file javajava org json from filejson file read in javaread file json javajava read json file readjava open json filejava code to read json fileopen json file jaload json file computer craftjava read json file datause json file in javareading from json file javajava access json fileload json file with javaread jsonfile javajava read jsonfilejava use json filejava reading out json fileread json file from package javajava 8 how to read json fileaccessing json file in javahow read json file in javajson file to json objectreading json file in javause json file javadecode json javaorg json java read json fileget json file as json string javajava json read from fileread json file javareading json file javahow to access json objects from a file in javaread java object from json fileread from json file javahow to read json file to json string in javaload json document in javajava load json filehow to load json file in javajava make application read json filehow to access json from file javaparse json files javajava read json from filejson save and load from jsonarrayjava how to read a json fileload json files jshow to read json file in java without libraryread a json file in javahow you can read json file in javahow to open json file in javajava json fileshow to read the json file in javaload json from file javaread json file on javajsonobject from json filefile read json javaparse json file in javaread json file as json string javajava load json file to objectread json file from directory java 8read json in javadecode json file in java tutorialhow to read json file with javareading a json file in javaread json file in json object javajava load json from internetjavascirpt load jsonjava read json file to json stringjava how to read json filejava reading a json fileparse json file to json object javasimple way to read json file javaload json from file javascriptread json file java whit org jsonread fron json file in javahow to read a jason object from jason file javajava import data from json fileread json files javaread json file using javaread json javajava parse json filehow to read json file javaread the json from the file in java read json file in javajava write json to filejava read jsonobject from filejson file in java read json file javajava import json filejs load json fileread json file and load to object in javareading json java localjson from file javajson file javahow to read json file in org json javaimport json file in javaload json file javahow to import data from json file in java eclipsejava read json file into objectread external json file in javaread json file with jsonobject javawrite json javaread json file to jsonobject javajson files in javawrite json file in javajava load json file