Output content as JSON
With a combination of Template, Format, and Output, you can publish page content as a JSON file.
Template
Create a Template using skip tags and a "dummy" surrounding element:
HTML
<!--#cascade-skip--><pass-through><system-region name="DEFAULT"/></pass-through>
Format
Generate valid JSON and surround it with a #protect-top code section. In Velocity, SerializerTool.toJson converts an XML string or JDOM Element to JSON.
Velocity
#set ($callingPage = $_XPathTool.selectSingleNode($contentRoot, "//calling-page/system-page"))
<!--#protect-top
$_SerializerTool.toJson($callingPage, true)
#protect-top-->
Or in XSLT:
XML
<xsl:comment>#protect-top
...JSON content here...
#protect-top</xsl:comment>
Output
Create a new Output in your page Configuration:
- Type of Data — JSON
- File Extension — .json
- Template — the Template you created above
- Regions — apply the Format you created and a calling page Index Block to the
DEFAULTregion
See How do I create a "calling page" Index Block? if you don't have one yet.