Skip to main content

A Python package to parse JSON and JSON templates

Project description

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

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

jsonplate-0.0.1.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

jsonplate-0.0.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file jsonplate-0.0.1.tar.gz.

File metadata

  • Download URL: jsonplate-0.0.1.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for jsonplate-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c0f37bdd70ec2d7076824fddd1b93397d92fc635af4b722fb9832aeeb50336c0
MD5 07773f671279a46c2fa52b2e0bd24185
BLAKE2b-256 f9de510ebecfb9d116ed953a6ade208db2fb04db0b139e12aba5a086e1aa5659

See more details on using hashes here.

File details

Details for the file jsonplate-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: jsonplate-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for jsonplate-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7d39f3390ee5d1bf66e8f2d5beaca9fad797f966ee23097f76dc79519f2f5f6
MD5 d5584c3169f1c034db9d78b25487898b
BLAKE2b-256 5f28332d0b1c8432a4eef806119cff19e4dca96259fbccf3a82ce37478e801a0

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