A simple python script to convert JSON to DOCX.
clone https://github.com/erictherobot/json-to-word.git json-to-docx
cd json-to-docx
pip3 install -r requirements.txt
python3 json-to-docx.py
Once you run this, it will generate a data.docx file in the same directory. You can change the input and output file names in the script. Eventually, I will add command line arguments to make it more flexible.
[
{
"name": "John",
"age": 30,
"city": "New York"
},
{
"name": "Jane",
"age": 25,
"city": "Los Angeles"
}
]
| name | age | city |
|---|---|---|
| John | 30 | New York |
| Jane | 25 | Los Angeles |
json-to-docx.pyfrom docx import Document
import pandas as pd
import json
# Load the JSON data
() f:
data = json.load(f)
df = pd.DataFrame(data)
doc = Document()
table = doc.add_table(rows=, cols=(df.columns))
i, column (df.columns):
table.cell(, i).text = column
index, row df.iterrows():
cells = table.add_row().cells
i, value (row):
cells[i].text = (value)
doc.save()
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT
Please consider Buying Me A Coffee. I work hard to bring you my best content and any support would be greatly appreciated. Thank you for your support!