🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

docx-json-replacer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docx-json-replacer

Replace template text in DOCX files with values from JSON

0.2.0
PyPI
Maintainers
1

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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts