evidens / json2csv

Converts JSON files to CSV (pulling data from nested structures). Useful for Mongo data
MIT License
264 stars 97 forks source link

list indices must be integers, not str #31

Open ernohorvath opened 8 years ago

ernohorvath commented 8 years ago

Tried gen_outline.py and failed. Got the following error, as I'm not a developer I have no clue what have I missed.. Traceback (most recent call last): File "gen_outline.py", line 85, in main() File "gen_outline.py", line 75, in main outline = make_outline(args.json_file, args.each_line, args.collection) File "gen_outline.py", line 50, in make_outline key_map = gather_key_map(iterator) File "gen_outline.py", line 31, in gather_key_map for d in iterator: File "gen_outline.py", line 26, in coll_iter for obj in data[coll_key]: TypeError: list indices must be integers, not str

It's a standard mongodb json extract.

evidens commented 8 years ago

For MongoDB you need to specify --each-line (JSON usually only has one object per file but Mongo breaks that rule and puts a bunch in the same file).

python gen_outline.py --each-line <yourfile>
python json2csv.py --each-line <yourfile> <outline file from previous step>

Hope that helps. I'll update the README with a call-out for Mongo so it's clearer to the next person.