Parsing a JSON String using Jquery and Velocity


If you have a field on a content type that stores a JSON string, you can parse the string using a combination of Velocity and JQuery.

JQuery provides a parseJSON function that receives a JSON string and returns a Javascript Object.

You can find more information on how to use this function on the JQuery website:


<script language="JavaScript">
${esc.h}${esc.h}${esc.d}content is your content object, and myJSONString is the field that stores the JSON string
var obj = jQuery.parseJSON('${esc.d}content.myJSONString');
${esc.h}${esc.h}You can get the values from the resulting Javascript object. 
${esc.h}${esc.h}This example assumes the JSON string has a name value like this: {"name":"John"}

Have you created code you'd like to share with the dotCMS community?

Share your code Become a Contributor