diff options
Diffstat (limited to 'tpl/encoding')
-rw-r--r-- | tpl/encoding/encoding.go | 4 | ||||
-rw-r--r-- | tpl/encoding/encoding_test.go | 2 | ||||
-rw-r--r-- | tpl/encoding/init.go | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/tpl/encoding/encoding.go b/tpl/encoding/encoding.go index 4b02c426a..d9c2bdfd6 100644 --- a/tpl/encoding/encoding.go +++ b/tpl/encoding/encoding.go @@ -50,9 +50,9 @@ func (ns *Namespace) Base64Encode(content interface{}) (string, error) { return base64.StdEncoding.EncodeToString([]byte(conv)), nil } -// Jsonify encodes a given object to JSON. +// Jsonify encodes a given object to JSON, returning pretty printed output. func (ns *Namespace) Jsonify(v interface{}) (template.HTML, error) { - b, err := json.Marshal(v) + b, err := json.MarshalIndent(v, "", " ") if err != nil { return "", err } diff --git a/tpl/encoding/encoding_test.go b/tpl/encoding/encoding_test.go index 8242561b6..fdb12e349 100644 --- a/tpl/encoding/encoding_test.go +++ b/tpl/encoding/encoding_test.go @@ -88,7 +88,7 @@ func TestJsonify(t *testing.T) { v interface{} expect interface{} }{ - {[]string{"a", "b"}, template.HTML(`["a","b"]`)}, + {[]string{"a", "b"}, template.HTML("[\n \"a\",\n \"b\"\n]")}, {tstNoStringer{}, template.HTML("{}")}, {nil, template.HTML("null")}, // errors diff --git a/tpl/encoding/init.go b/tpl/encoding/init.go index bad1804de..902a2b003 100644 --- a/tpl/encoding/init.go +++ b/tpl/encoding/init.go @@ -47,7 +47,7 @@ func init() { ns.AddMethodMapping(ctx.Jsonify, []string{"jsonify"}, [][2]string{ - {`{{ (slice "A" "B" "C") | jsonify }}`, `["A","B","C"]`}, + {`{{ (slice "A" "B" "C") | jsonify }}`, "[\n \"A\",\n \"B\",\n \"C\"\n]"}, }, ) |