vinay20045 / json-to-csv

Nested JSON to CSV Converter
https://askvinay.com/post/converting-nested-json-to-csv-8-december-2013.html
MIT License
287 stars 219 forks source link

NameError: global name 'reduced_item' is not defined #22

Closed ron819 closed 6 years ago

ron819 commented 6 years ago

This is the format of my JSON file: image

I want to unpack the results to CSV file with the script. Basically it should be 12 rows of data in CSV.

The script fails (Python 2.7):

    reduced_item[to_string(key)] = to_string(value)
NameError: global name 'reduced_item' is not defined
vinay20045 commented 6 years ago

Have you changed something in the script? Try running it without changing anything first and then trace back your changes one by one to see where the issues might be.

Lines 82 and 41 will be a good place to start.

ron819 commented 6 years ago

@vinay20045 All I did was to replace the main function with another function name so that I can call this script from my script. Basically to import your script to my project and then simply use it.

In any case when I run the script directly it doesn't give me the expcted result. It gives:

results

  11   10   13   12   1   0   3   2   5   4   7   6   9   8

vinay20045 commented 6 years ago

Yeah, that won't work. You have to do some more changes to be able to use it as a lib. There is already an open issue #6 and I'm yet to get around to working on it.

If you do make it work, please consider sending a PR and I will gladly review it.