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:

from jsoninja import Jsoninja

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

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

Allows multiple replacements 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",
# }

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

from jsoninja import Jsoninja

jsoninja = Jsoninja()
template = {
    "{{variable_name}}": "bar",
}
replacements = {
    "variable_name": "foo",
}
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.0.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

jsoninja-1.0.4-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsoninja-1.0.4.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for jsoninja-1.0.4.tar.gz
Algorithm Hash digest
SHA256 61293065ed7b691a1efd167b7b26c12bd4c7e163d2bac77e4f7a32636cea9f20
MD5 5de09792bb0f3e5045f71b08344438c2
BLAKE2b-256 a889c1d569c12da31d292a035734937618130a0f33f00e1286df970c6dc3dbfa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsoninja-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for jsoninja-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 895b57e5c2e06443b749f02f641de54e1fc52327a3ca084e9a436fc434df7b6d
MD5 1679ac09e82436892f11f3109e9b285c
BLAKE2b-256 b7ffc225183e707140e21d28c9309f57a5efe47914848da56378396d9965de2a

See more details on using hashes here.

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