I have a big JSON file (> 1Gb) which includes an array of objects:
[
{
"Property1":"value",
"Property2":{
"subProperty1":"value",
"subProperty2":[
"value",
"value"
]
},
"Property3":"value"
},
{
"Property1":"value",
"Property2":{
"subProperty1":"value",
"subProperty2":[
"value",
"value"
]
},
"Property3":"value"
}
]
Currently, I parse this JSON using Gson but it doesn't work, I have following error: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
In order to parse this JSON, I did following:
reader = new BufferedReader(new FileReader(jsonFile));
Gson gson = new GsonBuilder().create();
Type typeArray = new TypeToken<List<String>>(){}.getType();
List<String> topics = gson.fromJson(reader, typeArray);
I want to parse this JSON array as String Array. In other words, I want a Java list of string instead of a Java list of objects. Like that :
topics[0] = "{\"Property1\":\"value\",\"Property2\":{\"subProperty1\":\"value\",\"subProperty2\":[\"value\",\"value\"]},\"Property3\":\"value\"}";
topics[1] = "{\"Property1\":\"value\",\"Property2\":{\"subProperty1\":\"value\",\"subProperty2\":[\"value\",\"value\"]},\"Property3\":\"value\"}";
Thank you :)