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

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")
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.1.0.tar.gz (6.1 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.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docx_json_replacer-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 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.1.0.tar.gz
Algorithm Hash digest
SHA256 36d617193281c1e0eadaa951835be7caab9a6d1fd4322c8045241b498cc0efde
MD5 061ead25b154820ce841fbab11ddff85
BLAKE2b-256 1ebefa44ef3c03f9bc5e8e7eff129aa8e889471822aa06f32e4eebf409cc2ac0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docx_json_replacer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f90481ee3a8abac8316d144dd5cab4759db0670a29915f7ded9f1b3381e19b11
MD5 a06ffce5b34d99e6f814fc1f2c736e79
BLAKE2b-256 383b8fb2efc48e8743b8829a9c1f82be225a5a28eb832487c1bf8e207adae1c7

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