Replace template text in DOCX files with values from JSON
Project description
docx-json-replacer
A Python library and CLI tool for replacing template text in DOCX files with values from JSON.
Installation
pip install docx-json-replacer
# or
pip3 install docx-json-replacer
Usage
CLI
docx-json-replacer file.docx data.json
This will create file_replaced.docx with template placeholders like {key} replaced with values from your JSON file.
Python Library
from docx_json_replacer import DocxReplacer
replacer = DocxReplacer("template.docx")vb
replacer.replace_from_json({"name": "John", "date": "2025-06-25"})
replacer.save("output.docx")
Template Format
Use {{key}} placeholders in your DOCX file that match keys in your JSON:
JSON:
{
"name": "John Doe",
"company": "Example Corp"
}
DOCX template:
Hello {{name}}, welcome to {{company}}!
Result:
Hello John Doe, welcome to Example Corp!
Local Development
Run tests:
python -m pytest tests/ -v
Test CLI locally:
python docx_json_replacer/cli.py tests/fixtures/template.docx tests/fixtures/data.json -o output.docx
python docx_json_replacer/cli.py tests/fixtures/doc_template.docx tests/fixtures/data.json -o output.docx
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docx_json_replacer-0.3.0.tar.gz.
File metadata
- Download URL: docx_json_replacer-0.3.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b07a868a3e7f0433d7cf3f0e53d1443ed24dca9b31d2a3b6eacca18dd55cf61
|
|
| MD5 |
1b2a40b10bd1a9695eb1be89cab6b911
|
|
| BLAKE2b-256 |
1a6b9287b07a9eaab23c0f3f7b7b930e6494562ffaba6c713ae2b146c152f3b6
|
File details
Details for the file docx_json_replacer-0.3.0-py3-none-any.whl.
File metadata
- Download URL: docx_json_replacer-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e5a43b41125b859ac50b92d3632be284444bc81fa3eaf2b03aed1b33fc13b5b
|
|
| MD5 |
39a93c6f60ba20559f89797a0d3ccfce
|
|
| BLAKE2b-256 |
8e44ab77af55c8d1ec65a19e5070672f1535c3190d0e81f25763dd8e86360771
|