Creating a JSON file

This piece of code grabs the latest packages from our site and creates a JSON file.

  1. $response.setHeader("Content-Type""application/json")  
  2.   
  3. #set($limit = '10')  
  4. #set($orderBy='modDate desc')  
  5. #set($query="+structureName:NAMEOFSTRUCTURE")  
  6.   
  7. #set ($listItems = "")  
  8. #set ($listItems = $dotcontent.pull($query,$limit,$orderBy))  
  9.   
  10. #set ($myList = $contents.getEmptyList())  
  11. #set ($mymap = $contents.getEmptyMap())  
  12.   
  13. ## Do a loop through the structure and populate a title (or other field)
  14.     #set($dummy = $mymap.put("title","$list.title"))  
  15. ##end
  16. #set($myjson = $json.generate($mymap))     
  17. #set($dummy = $myList.add($myjson))  
  18.   
  19. ##Now output the contents you created above into a JSON format:
  20. {"contentlets":$myList}  
comments powered by Disqus