I have a JSON object in string that looks like
'{"key1":"value1", "key2": "value2", "key3": "value3"}'
I can use json.loads to make that into a JSON object, but when I try to print it in HTML, it prints the entire JSON object like
{"key1":"value1", "key2": "value2", "key3": "value3"}
my function looks like:
def jsonPretty(json_string):
return json.loads(json_string)
and in HTML/Django:
{{kvpair|jsonLoadsPretty}}
However I want it to print
key1 value1
key2 value2
key3 value3
The format can vary a little, but I want each key-value pair to separate by a \n, and the brackets should be removed.
What would be the best way of doing this?
EDIT:
I'm using {% with kvpair|jsonPretty as kvjson %} before running a for loop with
{% for k, v in kvjson.items %}
<p> {{k}} {{v}}</p>
and now it works fine. Thanks for @Andrey Shipilov 's help!