Skip to content

Instantly share code, notes, and snippets.

@avin
Created May 19, 2023 07:50
Show Gist options
  • Save avin/8189d0db58fc81d9242b82eb5fefc7db to your computer and use it in GitHub Desktop.
Save avin/8189d0db58fc81d9242b82eb5fefc7db to your computer and use it in GitHub Desktop.
Freemarker dump all data
<#-- JSON stringify -->
<#function stringify obj>
<#if !obj??>
<#return 'undefined'>
</#if>
<#if obj?is_date>
<#return '"' + obj?string("yyyy-MM-dd HH:mm:ss") + '"'>
</#if>
<#if obj?is_boolean || obj?is_number>
<#return obj?string>
</#if>
<#if obj?is_enumerable>
<#local str = '['>
<#list obj as x>
<#local str = str + stringify(x)>
<#if x_has_next>
<#local str = str + ',<br>'>
</#if>
</#list>
<#return str + ']'>
</#if>
<#if obj?is_string>
<#return '"' + obj?js_string + '"'>
</#if>
<#if obj?is_hash || obj?is_hash_ex>
<#local str = '{'>
<#local arr = [] >
<#local keys = obj?keys>
<#list keys as x>
<#if x!='class' && obj[x]??>
<#local arr = arr + [x]>
</#if>
</#list>
<#list arr as x>
<#local str = str + '"' + x + '" :' + stringify(obj[x])>
<#if x_has_next>
<#local str = str + ',<br>'>
</#if>
</#list>
<#return str + '}'>
</#if>
<#return ''>
<#if obj?is_string>
<#return '"' + obj?js_string + '"'>
</#if>
</#function>
${stringify(.data_model)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment