This macro takes a Freemarker model and prints it out as JSON. Output is compressed to a single line.
<#import "json.ftl" as json>
<@json.stringify your_model_here />
Escape the generated JSON with the second argument to <@json.stringify>
. The options are html
and js_string
.
<meta name="extraData" content='<@json.stringify extra_data "html" />' />
<script type="text/javascript">
var myExtraJSON = '<@json.stringify extra_data "js_string" />';
// of course, if you need the data, not a JSON string, you can do this:
var myExtraData = <@json.stringify extra_data />;
</script>