Created
January 18, 2016 13:59
-
-
Save ruudud/698035f96e860ef85d3f to your computer and use it in GitHub Desktop.
Freemarker JSON dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#assign foo><@objectToJson object=data.myobj /></#assign> | |
${foo?html} | |
<#macro objectToJson object> | |
<@compress single_line=true> | |
<#if object?is_hash || object?is_hash_ex> | |
<#assign first="true"> | |
{ | |
<#list object?keys as key> | |
<#if first="false">,</#if> | |
<#assign foo = key /> | |
<#assign value><@objectToJson object=object[key]!"" /></#assign> | |
"${key}": ${value?trim} | |
<#assign first="false"> | |
</#list> | |
} | |
<#elseif object?is_enumerable> | |
<#assign first="true"> | |
[ | |
<#list object as item> | |
<#if first="false">,</#if> | |
<#assign value><@objectToJson object=item /></#assign> | |
${value?trim} | |
<#assign first="false"> | |
</#list> | |
] | |
<#else> | |
"${object?trim}" | |
</#if> | |
</@compress> | |
</#macro> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.