Skip to main content

jsonplate

jsonplate is a lightweight, standards-compliant JSON templating engine for Python. It enables dynamic generation of JSON by allowing parameter substitution in values, keys, and strings.

🔧 Features

  • ✅ Spec-compliant JSON parser
  • 🧩 Parameter substitution in:
    • Object keys
    • Object or array values
    • String literals via {{variable}} syntax
  • 🧱 Reusable templates via load_template
  • 🔍 Variable introspection via variable_names
  • 🚫 No logic blocks, loops, or control flow

📦 Installation

Install via PyPI:

pip install jsonplate

🚀 Usage

Simple Usage

import jsonplate

template = '''
{
    "{{greeting_key}}": "Hello, {{name}}!",
    "values": [1, 2, 3, param_value],
    "config": {
        "enabled": true,
        param_key: 123
    }
}
'''

result = jsonplate.parse(
    template,
    greeting_key="message",
    name="Alice",
    param_value=42,
    param_key="threshold"
)

print(result)

Output:

{
    "message": "Hello, Alice!",
    "values": [1, 2, 3, 42],
    "config": {
        "enabled": true,
        "threshold": 123
    }
}

Reusable Templates

You can parse once and render multiple times with different parameters:

template = jsonplate.load_template('{"user": "{{name}}"}')

template(name="Alice")  # {"user": "Alice"}
template(name="Bob")    # {"user": "Bob"}

⚠️ Errors

All parsing and templating errors inherit from the base jsonplate.errors.JSONError class.

You may specifically catch:

  • JSONTemplaterError: raised when template substitution fails

  • JSONParserError: raised when a syntax violation is encountered

  • JSONLexerError: raised when tokenization fails

Metadata

Release files for jsonplate 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonplate 0.0.1
File Size Uploaded
jsonplate-0.0.1.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonplate 0.0.1
File Interpreter ABI Platform
jsonplate-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / jsonplate-0.0.1.tar.gz

Download URL jsonplate-0.0.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c0f37bdd70ec2d7076824fddd1b93397d92fc635af4b722fb9832aeeb50336c0
BLAKE2b-256 checksum
How to use checksums
f9de510ebecfb9d116ed953a6ade208db2fb04db0b139e12aba5a086e1aa5659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / jsonplate-0.0.1-py3-none-any.whl

Download URL jsonplate-0.0.1-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7d39f3390ee5d1bf66e8f2d5beaca9fad797f966ee23097f76dc79519f2f5f6
BLAKE2b-256 checksum
How to use checksums
5f28332d0b1c8432a4eef806119cff19e4dca96259fbccf3a82ce37478e801a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page