This might be a very silly one but I'd like to know how I can create a json file that looks like this:
{
"aString":"foo",
"anArray":
[
"foo",
"bar",
"obj"
],
"anInteger":100
}
instead of this: {"aString":"foo","anArray":["foo","bar","obj"],"anInteger":100}
Here's the code that creates the second one:
public class Main
{
public static final String defDir = "C:\\Users\\*UserName*\\Desktop\\Java\\Test\\src\\Files\\";
public static void main(String[] args) {
JSONObject obj = new JSONObject();
obj.put("aString", "foo");
obj.put("anInteger", 100);
JSONArray list = new JSONArray();
list.add("foo");
list.add("bar");
list.add("obj");
obj.put("anArray", list);
try (FileWriter file = new FileWriter(defDir + "test.json"))
{
file.write(obj.toString());
file.flush();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
And how do I read multiple-line json with JSON.simple