• JSON To CSV – Python Json Tutorial

    Use this code to parse Json to csv or Excel. Actually, this code write to a csv file, which can be opened in a Excel file as well. So, both are same CSV or Excel.

    If you are not sure about how to read or write data to a CSV file from Python, then refer this page for more info. If you are looking to parse Json using a Excel vba code directly, then here is complete guide & code.

    Python JSON – Example

    Copy this sample file and store it in D drive as Json.txt file. This file will be given as input for the Json parser code.

    JSON Parser Code

    Just check that you have the sample file in this path to execute this code. “d:/json.txt”. If you already have a json file, then replace the file path in the below code then press F5 to execute this code in the Python IDE.

    Once this file is written to the CSV, open the output file in a Notepad, Textpad or Excel app to veiw the JSON data being converted to different format.

    Though it is a Json parser, one should know the field names and how they are arranged in the JSON file. We will be able to convert or read each node only if we know the node names if it is arranged in multiple levels.

    For examplel, in the above sample file, we have three fields inside category. So, we have to explicitly specify the name of each node to get its value.

    Previous Post:
    Next Post: