[Answered ]-Unable to use JSON.parse in my django template

1👍

Try outputting it as a string:

<script type = text/javascript>    
  var ob2 = JSON.parse( "{{ data1 }}" );
  document.write(ob2);
</script>

If this is not producing the results, I suggest just printing {{ data1 }} on screen and seeing exactly what is being returned by Django.

1👍

Besides The Brewmaster’s answer, the other problems are:

data1 = json.loads(str1)

That turns the JSON string back into a Python data structure. Just send str1 itself to the template, and call it a as that’s what you use in the template:

return render(request, 'dashboard/new 1.html',{'a' : str1})

0👍

Try this by remove Parse

 <script type = text/javascript>    
   document.write("{{ data1 }}");
 </script>

Leave a comment