Skip to main content

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docx_json_replacer-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docx_json_replacer-0.2.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file docx_json_replacer-0.2.0.tar.gz.

File metadata

  • Download URL: docx_json_replacer-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for docx_json_replacer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 751f45703ced0f3ead250e76b061cf7d37ad69f5f82704f5596d8a17b436a4c1
MD5 dce3682f5d2a4fab412c9b0780a8fc79
BLAKE2b-256 1cf71081cb39780d6cb9ab48b1dca3482ab1c541d399813cfcd66dac63de114d

See more details on using hashes here.

File details

Details for the file docx_json_replacer-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for docx_json_replacer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c00314f329730e97d8ee3f57ec408196eae4ddcc8ac1ad3b8698d4b378617cb2
MD5 3856b212e782e5acc2fe627355a6e10b
BLAKE2b-256 215c44cab49d7423bc562a17c8a69688847ee3b0564ca82bcd95fd751cca100c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page