Skip to content

Instantly share code, notes, and snippets.

@peterlie
Last active November 27, 2015 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterlie/205a806c2c9513670375 to your computer and use it in GitHub Desktop.
Save peterlie/205a806c2c9513670375 to your computer and use it in GitHub Desktop.
JSON.stringify example using Django template
/*jslint browser: true*/
(function ($) {
'use strict';
$(document).ready(function () {
if ($('#rawJson').length) {
var rj = $('#rawJson').text();
$('#fmtJson').html(JSON.stringify(JSON.parse(rj), null, 4));
}
});
}(window.jQuery));
{% if raw_json %}
<div id="rawJson" class="hidden"> {% autoescape off %} {{raw_json}} {% endautoescape %} </div>
<pre>
<div id="fmtJson">
</div>
</pre>
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment