nix_stack nix_stack - 2 months ago 11
JSON Question

Error while parsing JSON from analytics

I need help with below.

I have json data from Google analytics in below form :

{"visitNumber":"3","fullVisitorId":"33283173096445"}
{"visitNumber":"2","fullVisitorId":"58516104158964"}
...............(upto 100k records)


and java code I have is :

JsonParser parser = new JsonParser();
JsonElement root = parser.parse(jsonData);


based on GSON libraries. I am getting "MalformedJsonException" while running this.

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected EOF at line 1 column 53

Answer

I tried below and it works.

        BufferedReader br = new BufferedReader(fileReader);
        String line = br.readLine();
        JsonParser parser = new JsonParser();
        JsonObject root = (JsonObject)parser.parse(line);;
Comments