go - How to print JSON on golang template? -


i need object in client side, converted json using json.marshal , printed template. object getting printed escaped json string.

i'm expecting var arr=["o1","o2"] var arr="[\"o1\",\"o2\"]"

i know can json.parse in client side, way?

here how i'm printing in template:

{{ marshal .arr }}

here marshal function:

"marshal": func(v interface {}) string {   a, _ := json.marshal(v)   return string(a) }, 

in js context normal strings gets escaped. should have converted template.js type before printing.

ref: http://golang.org/pkg/html/template/#js

this new marshal function:

"marshal": func(v interface {}) template.js {   a, _ := json.marshal(v)   return template.js(a) }, 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -