Forum Discussion
thinkclay
6 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>
DougS
5 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