with open(filepath) as filedata:
decks = json.load(filedata)
I'm using the above code to try and load a JSON file created by a Scrapy Spider. I recently reran the scraper to get an updated JSON file and the format should be the same but the lines above through the following error when I try to load the new file. (note this isn't appended to any existing file).
Traceback (most recent call last):
File "/Users/tonysitu/Documents/workspace/Mtg/ArchetypeAnalysis/analyze/deck_stats.py", line 215, in launcher
standard = constructFormat()
File "/Users/tonysitu/Documents/workspace/Mtg/ArchetypeAnalysis/analyze/deck_stats.py", line 98, in constructFormat
decks = json.load(deckData)
File "/Users/tonysitu/anaconda3/lib/python3.4/json/__init__.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/Users/tonysitu/anaconda3/lib/python3.4/json/__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "/Users/tonysitu/anaconda3/lib/python3.4/json/decoder.py", line 346, in decode
raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 120 column 835 - line 306 column 945 (char 99352 - 254693)
I've validated the JSON file using various applications on the web and none have raised an error. In addition all the dictionaries are enclosed by a single set of [ ] brackets. I haven't changed my scraper and the data format seems to be the same as my previously working JSON file. I'm not sure what could be causing the error. I would appreciate any advice and but I'd like to avoid using json.loads() and going through the file line by line.
[
{"cards": ["Den Protector", "Duskwatch Recruiter", "Hidden Dragonslayer", "Jace, Vryn's Prodigy", "Sylvan Advocate", "Bounding Krasis", "Nissa, Vastwood Seer", "Reflector Mage", "Tireless Tracker", "Archangel Avacyn", "Dromoka's Command", "Collected Company", "Ojutai's Command", "Canopy Vista", "Evolving Wilds", "Forest", "Fortified Village", "Island", "Lumbering Falls", "Plains", "Port Town", "Prairie Stream", "Clip Wings", "Declaration in Stone", "Den Protector", "Dromoka's Command", "Hidden Dragonslayer", "Negate", "Lantern Scout", "Ojutai's Command", "Sigarda, Heron's Grace", "Tragic Arrogance"], "quantities": ["\n1\n", "\n4\n", "\n1\n", "\n3\n", "\n4\n", "\n4\n", "\n1\n", "\n4\n", "\n3\n", "\n2\n", "\n3\n", "\n4\n", "\n1\n", "\n3\n", "\n4\n", "\n3\n", "\n1\n", "\n2\n", "\n4\n", "\n3\n", "\n1\n", "\n4\n", "\n2\n", "\n2\n", "\n1\n", "\n1\n", "\n1\n", "\n3\n", "\n1\n", "\n1\n", "\n1\n", "\n2\n"], "name": ["Bant Company by Kevin Sauls Deck"]},
{"cards": ["Deathcap Cultivator", "Duskwatch Recruiter", "Jace, Vryn's Prodigy", "Rattlechains", "Sylvan Advocate", "Bounding Krasis", "Eldrazi Skyspawner", "Nissa, Vastwood Seer", "Reflector Mage", "Tireless Tracker", "Sigarda, Heron's Grace", "Declaration in Stone", "Dromoka's Command", "Nissa, Voice of Zendikar", "Collected Company", "Canopy Vista", "Evolving Wilds", "Forest", "Island", "Lumbering Falls", "Plains", "Prairie Stream", "Yavimaya Coast", "Dispel", "Clip Wings", "Declaration in Stone", "Den Protector", "Felidar Cub", "Negate", "Stratus Dancer", "Lantern Scout", "Ojutai's Command", "Archangel Avacyn"], "quantities": ["\n1\n", "\n4\n", "\n1\n", "\n2\n", "\n4\n", "\n4\n", "\n2\n", "\n1\n", "\n4\n", "\n2\n", "\n1\n", "\n1\n", "\n3\n", "\n1\n", "\n4\n", "\n4\n", "\n4\n", "\n3\n", "\n2\n", "\n4\n", "\n3\n", "\n4\n", "\n1\n", "\n2\n", "\n1\n", "\n1\n", "\n2\n", "\n1\n", "\n2\n", "\n1\n", "\n1\n", "\n2\n", "\n2\n"], "name": ["Bant Company by Jessy Hefner Deck"]}
...
]