I receive a json payload like below:
{
"address": {
"summary": "my home's address"
}
}
I have a JSON with jinja template:
{
"parent_elem": [{
"address": "{{DATA.address}}"
}]
}
Then, I try to copy the value from payload's address to template json via jinja.
with open('payload.json') as payload_file:
data = json.load(payload_file)
# Load the Jinja2 environment
env = Environment(loader=FileSystemLoader('.'))
template = env.get_template('jinja_template.json')
# Render the template with the variables
output = template.render(
DATA = data
)
return json.loads(output)
However, the code breaks on single quotes (home's keyword) and I end up getting this error:
json.decoder.JSONDecodeError: Expecting ',' delimiter:
How do I escape this single quote and get a perfect json from the template?
This is the json I receive from jinja: Clearly this is not a valid JSON
{
"parent_elem": [{
"address": "{'summary': "my home's address"}"
}]
}
If I remove the single quote from "home's" keyword in input json, this is what I get at output (which is a valid json)
{
"parent_elem": [{
"address": "{'summary': 'my homes address'}"
}]
}