Angel Ruiz
grails, how-to, javascript

How to render JSON properly (without escaping quotes) inside a GSP script tag

Angel Ruiz grails, how-to, javascript


Grails logo

This issue was encountered while using Grails version 2.3.11

In theory it should be as simple as:

  1. Return JSON in your model from your controller
def index() = {  
    [data: data as JSON]
}
  1. Render the model attribute without encoding using the raw() method
<r:script>  
    var data = ${raw(data)};
</r:script>  

Unfortunately this does not work, at least when you are using the resources plugin. You know it does not work because all the quotes have

Read More