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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -