Jsoninja is a library that allows you to generate JSON's from templates written with Python dicts.
Project description
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)