

Let's say you do that and have a new flattened dictionary named r. You could take the JSON formatted json_data above and unpack it manually, removing nested parts, which means looking through the response and making your own Python dictionary with only single level i.e. You need to essentially flatten the structure yourself, perhaps decide what is important or what you want to can leave out. under "result" there "fields" and then more values, and CSV files can't display that directly. JSON can be a valid nested object or a list. If the output file path is not provided the output will be dumped to STDOUT.
There is no simple way to write this directly to a CSV file, because there are nested structures: e.g. usage: python -m libjson2csv.csv2jsonThe issue is that is will parse it a little strangely. It can read straight from a JSON string (our text above). Once you have done that, you can do the following using Pandas to write the CSV file: import pandas as pd df pd.readjson (r) df.tocsv ('output.csv') Share Improve this answer Follow edited at 8:54 answered at 13:18 n1k31t4 14.4k 2 26 47 well that is perfect answer. I would suggest using Pandas, which can do a lot of the tedious work for you very easily. We can use the json module's function loads to load a string): json_data = json.loads(text) The response in this case is a raw string. We get the text data out by using the read() method: text = response.read()

Import json # Used to load data into JSON format It is in Python 2, but I will show you how to make it work in Python 3. On the page you linked there is actually a Python example on how to get the data.
