Skip to content

Instantly share code, notes, and snippets.

@victory-sokolov
Created December 31, 2019 09:28
Show Gist options
  • Save victory-sokolov/3fa3cb90b6a974f442e20018b9ddc56a to your computer and use it in GitHub Desktop.
Save victory-sokolov/3fa3cb90b6a974f442e20018b9ddc56a to your computer and use it in GitHub Desktop.
Read/Write JSON
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public static JSONObject readJSON(String file) throws IOException, ParseException {
JSONParser parser = new JSONParser();
FileReader config = new FileReader(file);
Object obj = parser.parse(config);
return (JSONObject) obj;
}
public static void writeToJSON(JSONObject jsonObject, String path) throws IOException {
FileWriter file = new FileWriter(path);
file.write(jsonObject.toJSONString());
file.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment