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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsontemplates-0.1.0.tar.gz.
File metadata
- Download URL: jsontemplates-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1f06186341c98d964b81d105c0ad615638df5882f593c265f6581eddf9a2a6b
|
|
| MD5 |
62368fccc57e7a6722fa0b2d656ad2fe
|
|
| BLAKE2b-256 |
c63cd1acbe78c9aa032dd93b45023dd8b23ad29c44bca2a99d0b1ba2417cab4d
|
File details
Details for the file jsontemplates-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jsontemplates-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e858df2803304a226f47109791d3582c934652ba7930176e40ec659a4c3373f
|
|
| MD5 |
d3dec13ca54952ca5e72ff8917a460b8
|
|
| BLAKE2b-256 |
2f7ad78588fdb0c1a38f4c97996127748e7aacc8bfa994f80650de243f001a23
|