Python 3 json2excel Library Script to Convert JSON File or Raw JSON to Excel (XLSX) File Full Project For Beginners

Python 3 json2excel Library Script to Convert JSON File or Raw JSON to Excel (XLSX) File Full Project For Beginners

 

Welcome folks today in this blog post we will be converting json file or raw json to excel file inside python using json2excel library. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install json2excel

 

After installing this library you need to make an app.py file and copy paste the following code

 

Raw JSON to Excel File

 

app.py

 

from json2excel import Json2Excel

if __name__ == '__main__':
    json2excel = Json2Excel(head_name_cols=["rank", "name"])
    # print(json2excel.run('./test.json'))

    jsons = [
        {
            "student_no": 1001,
            "name": "James",
            "score": 10,
            "class": "A-1",
            "rank": 1
        },
        {
            "student_no": 1002,
            "name": "Tome",
            "score": 91,
            "class": "A-1",
            "rank": 2
        },
    ]
    print(json2excel.run(jsons))

 

 

JSON File to Excel File

 

app.py

 

In this example we will create the file.json file inside the root directory

See also  Python 3 Radix Sort Algorithm Script to Sort Number Array in Ascending or Descending Order Full Example Project For Beginners

 

file.json

 

[
        {
            "student_no": 1001,
            "name": "James",
            "score": 10,
            "class": "A-1",
            "rank": 1
        },
        {
            "student_no": 1002,
            "name": "Tome",
            "score": 91,
            "class": "A-1",
            "rank": 2
        },
    ]

 

 

app.py

 

from json2excel import Json2Excel

if __name__ == '__main__':
    json2excel = Json2Excel(head_name_cols=["rank", "name"])
    
    print(json2excel.run("./file.json"))

 

 

Now if you run this python script by typing the below command as shown below

 

python app.py

 

 

 

Leave a Reply