Skip to main content

Jsoninja is a library that allows you to generate JSON's from templates written with Python data types.

Project description

Jsoninja

A library that allows you to generate JSON's from
templates written with Python data types.

Library version

Instalation

$ pip install jsoninja

Use Case Examples

You can use the main Python data types:

import jsoninja

template = {
    "foo": "{{variable_name}}",
}
replacements = {
    "variable_name": "bar",
}
result = jsoninja.replace(template, replacements)

# {
#   "foo": "bar",
# }

Allows multiple replacements of the same variable:

import jsoninja

template = {
    "message1": "{{message}}",
    "message2": "{{message}}",
    "message3": "{{message}}",
}
replacements = {
    "message": "I am duplicated!",
}
result = jsoninja.replace(template, replacements)

# {
#   "message1": "I am duplicated!",
#   "message2": "I am duplicated!",
#   "message3": "I am duplicated!",
# }

Use callback functions to generate the values to be replaced:

import jsoninja


def generate_password() -> str:
    return "super_secret_password"


template = {
    "password": "{{password}}",
}
replacements = {
    "password": generate_password,
}
result = jsoninja.replace(template, replacements)

# {
#   "password": "super_secret_password",
# }

Support for variables in the dict keys (replacements must be str, int, float or bool):

import jsoninja

template = {
    "{{variable_name}}": "bar",
}
replacements = {
    "variable_name": "foo",
}
result = jsoninja.replace(template, replacements)

# {
#   "foo": "bar",
# }

If you want to use a custom variable pattern, you can do that too:

from jsoninja import Jsoninja

# The pattern must include a capturing group for the variable name.
pattern = r"\$\{([a-zA-Z0-9_]+)\}"
jsoninja = Jsoninja(variable_pattern=pattern)

template = {
    "foo": "${variable_name}",
}
replacements = {
    "variable_name": "bar",
}
result = jsoninja.replace(template, replacements)

# {
#   "foo": "bar",
# }

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

jsoninja-1.2.0.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

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

jsoninja-1.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file jsoninja-1.2.0.tar.gz.

File metadata

  • Download URL: jsoninja-1.2.0.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jsoninja-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d142b85559e013febc0ad546a73cffafdb20db6d3d4d7febf675cd14b43b68d1
MD5 3a0d4689cb000a21751ee0055f51017e
BLAKE2b-256 dbd67f55aa7a4c586796d38723713ba0c598cf80719ea9328467ef3c5ad9e44a

See more details on using hashes here.

File details

Details for the file jsoninja-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: jsoninja-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for jsoninja-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ae07026dc1f67f64b7fa255bd5fe58e9fccc0ce0cd2b4c7c33c45dea1afd3df
MD5 774e32fbe7038fadef7ac7e8e5fe6640
BLAKE2b-256 fbf283440b956109b0b39fd062c7f70eaac188ad41b254cc215f8cadd349e55c

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