A small python module for populating json template files.
Project description
json-templates
A small python module for populating json template files.
Version 0.1.0
Accepts either a json string or a file path and a dictionary. json-template replaces the place holders found in the json with those found in the dictionary.
Below is a template example
{
"key":"hard coded value",
"key2":1,
"key3":"{{ variable }}",
"key4":"{% array %}"
}
Currently supports {{ variable }}
for single replacement and {% array %}
for iterable replacement.
For example given the following dictionary
{
"variable":"hello world",
"array":["foo","bar"]
}
The JSON would become
{
"key":"hard coded value",
"key2":1,
"key3":"hello world",
"key4":["foo","bar"]
}
Usage
import JsonTemplates
json_tmp = JsonTemplates()
result = json_tmp.load("template.json")
if result[0]:
new_dict = json_tmp.generate({"variable":"hello world","array":["foo","bar"]})
Methods
-
load(json_file_path) - Loads a JSON file
Returns a tuple (Success,error message or dictionary) -
loads(json_str) - Loads a JSON string
Returns a tuple (Success,error message or dictionary) -
generate(replacement_dict) - Takes in a dictionary of replacement values and generates a new dictionary with the placeholders replaced with the values in the dictionary
Returns a tuple (Success, error message or dictionary)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for jsontemplates-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e858df2803304a226f47109791d3582c934652ba7930176e40ec659a4c3373f |
|
MD5 | d3dec13ca54952ca5e72ff8917a460b8 |
|
BLAKE2b-256 | 2f7ad78588fdb0c1a38f4c97996127748e7aacc8bfa994f80650de243f001a23 |