Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

playframework JsValue in HTML Template

I'm trying to define a json object in the template with the JsValue of play (v2.2.2). The problem is, " is converted to "

@(org: db.Tables.OrganizationRow)

@import models.format.EntityFormat._
@import play.api.libs.json.Json

<script  type="text/javascript">
    var org = @Json.toJson(org);
</script>

results in:

{&quot;id&quot;:16,&quot;userid&quot;:&quot; ... more data ... };

How I'm able to get the correct json in the scala html template?

like image 698
pichsenmeister Avatar asked Jun 19 '14 15:06

pichsenmeister


1 Answers

Define it as Html so it doesn't automatically get escaped.

var org = @Html(Json.stringify(Json.toJson(org)));
like image 150
Michael Zajac Avatar answered Oct 20 '22 16:10

Michael Zajac