title: How to access elements of JSON object in view.gsp to use as parameters in an image call?
body: <p>I think I'm passing a JSON object from my controller to my view but I can't seem to access the discreet elements of the JSON. Please share your thoughts.</p>
  
  <ul>
  <li>How much of the DisplayRecentPortlet is required, should I be
  accessing the JSON elements there? </li>
  <li>Am I really passing JSON? </li>
  <li>How might I access the individual elements inside jsonObj to construct an
  img tag in the view?</li>
  </ul>
  
  <p><strong>DisplayRecentContoller.groovy</strong></p>
  
  <pre><code>package cssinstaviewer
  
  import groovy.json.*
  import grails.converters.JSON
  
  class DisplayRecentController {
  
      def view() { 
  
         def apiUrl = new URL("https://api.instagram.com/v1/users/STUFFTHATWORKS/media/recent/?client_id=STUFFTHATWORKS")
         def doc = new JsonSlurper().parseText(apiUrl.text)
         def jsonObj = new JsonBuilder(doc.data.images.low_resolution[0])
  
                          render(view:"view", model: [jsonObj: jsonObj as JSON])  
  
      }
  }
  </code></pre>
  
  <p><strong>DisplayRecentPortlet.groovy</strong></p>
  
  <pre><code>package cssinstaviewer
  
  import javax.portlet.*
  
  class DisplayRecentPortlet {
  
      def title = 'CSS Instagram Viewer'
      def description = '''
  CSS Instagram Viewer
  '''
      def displayName = 'CSS Instagram Viewer'
      def supports = ['text/html':['view']]
  
      //uncomment to declare events support
      //def events = [publish: ["event-1"], process: ["event-2"]]
  
      //uncomment to declare public render parameter support
      //def public_render_params = ["prp-1","prp-2"]
  
      // Used for liferay
      // @see http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/anatomy-of-a-portlet
       def liferay_display_category = "category.St. Scholastica"
  
      def actionView = {
          //TODO Define action phase for 'view' portlet mode
          portletResponse.setRenderParameter("prp-1", "value-1");
      }
  
      def eventView = {
          //TODO Define event phase for 'view' portlet mode.
          def eventValue = portletRequest.event.value
      }
  
      def renderView = {
          //TODO Define render phase for 'view' portlet mode.
          //Return the map of the variables bound to the view,
          //in this case view.gsp if it exists or render.gsp if not
          ['jsonObj':'jsonObj']
      }
  
      def resourceView = {
          //TODO define resource phase for 'view' portlet mode.
          //Render HTML as response
          render {
              html {
                  head()
                  body {
                      "Render me"
                  }
              }
          }
      }
  
      def actionEdit = {
          //TODO Define action phase for 'edit' portlet mode
          portletResponse.setEvent("event-1","event-1")
          portletResponse.setPortletMode(PortletMode.VIEW)
      }
  
      def renderHelp = {
          //TODO Define render phase for 'help' portlet mode
          //Return the map of the variables bound to the view,
          //in this case help.gsp if it exists or render.gsp if not
          ['mykey':'myvalue']
      }
  
      def doResource = {
          //TODO Define handling for default resource URL handling method, independent of porlet mode
          //Return the map of the variables bound to the view,
          //in this case resource.gsp
          ['mykey':'myvalue']
      }
  
      //invoked by setting 'action' param in resourceURL (as an example) to 'doSomethingAjaxy'
      def doSomethingAjaxy =  {
          //render JSON
          render(contentType:"text/json") {
              example(mykey:"myvalue")
          }
      }
  
      //invoked by setting 'action' param in eventURL (as an example) to 'handleThisEvent'
      def handleThisEvent =  {
          //render thisEvent.gsp
          render(view:"thisEvent")
      }
  
  }
  </code></pre>
  
  <p><strong>view.gsp</strong></p>
  
  <pre><code>&lt;%@page import="cssinstaviewer.DisplayRecentPortlet"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %&gt;
  &lt;div&gt;
   &lt;g:set var="instaImg" value="${jsonObj}" /&gt;
   instImg = ${instaImg}
   &lt;hr /&gt;
  jsonObj ${jsonObj}"
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>instImg = {"content":{"height":306,"width":306,"url":"http://scontent-a.cdninstagram.com/hphotos-xap1/t51.2885-15/925254_1484378108464185_1325554272_a.jpg"}} jsonObj {"content":{"height":306,"width":306,"url":"http://scontent-a.cdninstagram.com/hphotos-xap1/t51.2885-15/925254_1484378108464185_1325554272_a.jpg"}}"
  </code></pre>