You should be using a function to explicitly convert it to JSON, because of a few subtle differences between JSON and the default Python stringification:
A string in JSON technically must be delimited with
"
rather than'
, though parsers tend to accept the latter too (see the string rule on json.org)Bool literals are lowercase
If your data contains things other than numbers, strings, lists and dicts, using
str
on them will probably silently produce invalid JSON
Use a template filter such as django-jsonify:
{% load jsonify %}
...
{{ foo|jsonify }}