Forum Discussion
DougS
8 years agoKhoros Oracle
From the freemarker code added to the KB article, it looks like objecttojson is a studio macro that you include in your template. nathan or SuzieH do either of you have the code for the objecttojson macro that is referenced in this article?:
I'm guessing the code may be something similar to the one found on this blog post (so you may be able to re-create it yourself):
http://ericbrandel.com/2013/03/28/freemarker-container-to-json
-Doug
- thinkclay6 years agoGuide
I've adapted Eric Brandel's function for use in Khoros for easy copy/paste if anyone in the future needs it:
<#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 value><@objectToJson object=object[key] /></#assign> "${key}" : ${value} <#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} <#assign first="false"> </#list> ] <#else> "${object}" </#if> </@compress> </#macro>
- DougS5 years agoKhoros Oracle
Note that as of 19.6, we also have the following utils object for working with JSON:
https://developer.khoros.com/khoroscommunitydevdocs/reference/utils-for-json
-Doug
Related Content
- 2 years ago
- 2 years ago