This code allows you to display the page information, template information and content on the page as a json object. If you add this to the top of your template and pass a ?json=1 to your page, it will display your page information as a json object.
#[[
#if($request.getParameter("json"))
$response.setContentType("application/json")
#set($pageMap = $contents.getEmptyMap())
#set($dummy = $pageMap.put("dotPageContent", $dotPageContent.getContentObject().getMap()))
#set($dummy = $pageMap.put("dotTheme", $dotTheme))
#set($dummy = $pageMap.put("dotThemeLayout", $dotThemeLayout))
#foreach($key in $context.getKeys())
#if($key.startsWith("contentletList"))
#set($cons = $contents.getEmptyList())
#set($contentIds=$context.get("$key"))
#foreach($id in $contentIds)
#set($con = $dotcontent.find($id))
#if($con)
#set($dummy = $cons.add($con.getContentObject().getMap()))
#end
#end
#set($dummy = $pageMap.put("container-$key", $cons))
#end
#end
$json.generate($pageMap)
#stop
#end
]]#
.