0

I tried to load my twit data in python but I got some error. Below is my code for loading my data. And I am attaching the error message. I am guessing that my TwitData1.json data has some problems, so need to be handled... I am not sure how I can handle this. Thank you in advance.

import json, pprint

with open("TwitData1.json") as json_file:

  json_data = json.load(json_file)

  pprint(json_data)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-ba1a50c671e1> in <module>()
      2 
      3 with open("TwitData1.json") as json_file:
----> 4     json_data = json.load(json_file)
      5     json_data.close()
      6     pprint(json_data)

C:\Users\Jay\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\json\__init__.pyc in load(fp, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    288         parse_float=parse_float, parse_int=parse_int,
    289         parse_constant=parse_constant, object_pairs_hook=object_pairs_hook,
--> 290         **kw)
    291 
    292 

C:\Users\Jay\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\json\__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    336             parse_int is None and parse_float is None and
    337             parse_constant is None and object_pairs_hook is None and not kw):
--> 338         return _default_decoder.decode(s)
    339     if cls is None:
    340         cls = JSONDecoder

C:\Users\Jay\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.4.1.1975.win-x86_64\lib\json\decoder.pyc in decode(self, s, _w)
    366         end = _w(s, end).end()
    367         if end != len(s):
--> 368             raise ValueError(errmsg("Extra data", s, end, len(s)))
    369         return obj
    370 

ValueError: Extra data: line 2 column 1 - line 21 column 1 (char 2057 - 70650)
2
  • You should try running your data through a validator - the error message indicates that the data is not valid json. You can try jq to do this.
    – vikramls
    Commented Nov 24, 2014 at 5:33
  • Thanks so much. I am a quite new guy regarding python. This is helpful. Thank you again.
    – Jihoon
    Commented Nov 24, 2014 at 21:59

1 Answer 1

1

first I will use a json validator to validate that your json file is correct (just google json validator). My bet is that it isn't, the error message stated clearly that there is an error in line 2 column 1 - line 21 column 1. Extra data error usually occur when you have multiple json objects in a single json file.

json.loads('{"object" : "A"}{"object" : "B"}')
valueError: Extra data: line 1 column 16 - line 1 column 32 (char 16 - 32)

To load multiple json object place the 2 json objects into a single list

json.loads('[{"object" : "A"},{"object" : "B"}]')
[{u'object': u'A'}, {u'object': u'B'}]

I hope you will find this useful

Cheers!

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.