[PYTHON] How to convert Json file to CSV format or EXCEL format

JSON format files are hard to see. I want to convert to CSV or EXCEL. Share how to solve your worries.

In this article, I will introduce the conversion method of Json file using Python using Python and the conversion tool that can be done based on the WEB.

Method 1: Convert using Python

It's very easy to use.

1. Place the Json file you want to convert and the Python file in the same file hierarchy.

2. Please change 3 places in the program below.

--Change the "Json file name you want to convert" in the program to the Json file name you put in 1. --Please put the word written at the beginning of the Json file in "The word written at the beginning when you open the Json file". If the Json file starts like {" results ": [{" acl ": {" * ": {" read ": true, ..., please enter "results" in this case. --Change the "File name you want to output" in the program to the file name you want to output.

ConvertJsonToCsv.py


#-*-coding:utf-8-*-
################################################
#Purpose: Convert Json files to CSV.
################################################

import json
import csv

#Load JSON file
json_dict = json.load(open('Json file name you want to convert.json', 'r', encoding="utf_8_sig"))
#Extraction of list of dict
target_dicts = json_dict['The first word written when you open the Json file']

with open('File name you want to output.csv', 'w', encoding="utf_8_sig") as f:
    #Dialect registration
    csv.register_dialect('dialect01', doublequote=True, quoting=csv.QUOTE_ALL)
    #DictWriter creation
    writer = csv.DictWriter(f, fieldnames=target_dicts[0].keys(), dialect='dialect01')
    #Write to CSV
    writer.writeheader()
    for target_dict in target_dicts:
        writer.writerow(target_dict)

Method 2: Convert using a web service.

If it's okay to send the file to the server, I think it's easier to use this method.

Link

WEB service that can convert Json files to CSV online

Recommended Posts

How to convert Json file to CSV format or EXCEL format
How to convert JSON file to CSV file with Python Pandas
[Python] How to convert db file to csv
Convert json to excel
Convert Pascal VOC format xml file to COCO format json file
[Python] Convert CSV file uploaded to S3 to JSON file with AWS Lambda
How to paste a CSV file into an Excel file using Pandas
How to easily convert format from Markdown
How to convert csv to tsv in CLI
How to convert Python to an exe file
Convert matplotlib graphs to emf file format
[Python] Convert csv file delimiters to tab delimiters
Convert Excel data to JSON with python
How to convert DateTimeField format in Django
How to read a CSV file with Python 2/3
[Python] Convert from DICOM to PNG or CSV
How to create a JSON file in Python
[Python] How to read excel file with pandas
[Introduction to Python] How to handle JSON format data
Convert UTF-8 CSV files to read in Excel
Convert json format data to txt (using yolo)
How to read JSON
I convert AWS JSON data to CSV like this
How to convert a mel spectrogram back to a wav file
Convert / return class object to JSON format in Python
Python script to create a JSON file from a CSV file
Convert HTML to text file
Parse JSON file to object
Convert SDF to CSV quickly
Convert genbank file to gff file
[Python] How to change EXCEL file saved in xlsb to xlsx
[Python] How to output a pandas table to an excel file
How to read an Excel file (.xlsx) with Pandas [Python]
[Caffe] Convert mean file from binary proto format to npy format
Convert Excel file to text in Python for diff purposes
Function to convert Excel column to number
[Python] Write to csv file with Python
Output to csv file with Python
[Introduction to Python] How to parse JSON
After calling the Shell file on Python, convert CSV to Parquet.
How to convert 0.5 to 1056964608 in one shot
Normalize the file that converted Excel to csv as it is.
[Python] How to store a csv file as one-dimensional array data
How to convert Tensorflow model to Lite
How to convert from .mgz to .nii.gz
[ROS2] How to play a bag file with python format launch
How to create a config file
[Good By Excel] python script to generate sql to convert csv to table
[Note] How to deal with unicode error and No such file or directory (output table to excel file with pandas)
Convert XML document stored in XML database (BaseX) to CSV format (using Python)
How to put a line number at the beginning of a CSV file
[Python] How to read a csv file (read_csv method of pandas module)
Read CSV file with Python and convert it to DataFrame as it is
How to format a list of dictionaries (or instances) well in Python
Preprocessing with Python. Convert Nico Nico Douga tag search results to CSV format
Script to generate directory from json file
[Python] How to convert a 2D list to a 1D list
Convert (compress) formatted JSON string to 1-line JSON
Convert psd file to png in Python
Convert PDF attached to email to text format
Convert array (struct) to json with golang