Output content as JSON

With a combination of Template, Format, and Output, you can publish your page content as a JSON file.

Template

Create a Template using skip tags and a "dummy" surrounding element:

<!--#cascade-skip--><pass-through><system-region name="DEFAULT"/></pass-through>

Format

Generate valid JSON content and surround that content with a #protect-top code section. In Velocity, the SerializerTool.toJson method can be used to convert an XML string or JDOM Element to JSON.

Velocity example:

#set ($callingPage = $_XPathTool.selectSingleNode($contentRoot, "//calling-page/system-page"))
<!--#protect-top
$_SerializerTool.toJson($callingPage, true)
#protect-top-->

XSLT example:

<xsl:comment>#protect-top
...JSON content here...
#protect-top</xsl:comment>

Output

Create a new Output in your page Configuration with the following settings:

  • Type of Data: JSON
  • File Extension: .json
  • Template: choose the Template you created earlier.
  • Regions: apply the Format you created earlier and a calling page Index Block to the DEFAULT region.