Skip to main content

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

Project description

Jsoninja

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

Library version Supported Python versions

Instalation

$ pip install jsoninja

Use Case Examples

You can use the main Python data types:

from jsoninja import Jsoninja

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

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

Allows multiple substitutions of the same variable:

from jsoninja import Jsoninja

jsoninja = 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:

from jsoninja import Jsoninja


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


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

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

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.0.0.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

jsoninja-1.0.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page