]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: add example for json.HTMLEscape
authorKetan Parmar <ketanbparmar@gmail.com>
Thu, 31 Jan 2019 01:58:15 +0000 (07:28 +0530)
committerAndrew Bonventre <andybons@golang.org>
Tue, 26 Feb 2019 18:14:45 +0000 (18:14 +0000)
Change-Id: Ib00fcfd46eae27eea0a3d4cab4406f4c461fb57b
Reviewed-on: https://go-review.googlesource.com/c/160517
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/encoding/json/example_test.go

index 2031cba7938927fb08bbd93e05daf9738b7d34fc..4c075ddaa655f5e6de3119687daa117b24708672 100644 (file)
@@ -301,3 +301,11 @@ func ExampleValid() {
        // Output:
        // true false
 }
+
+func ExampleHTMLEscape() {
+       var out bytes.Buffer
+       json.HTMLEscape(&out, []byte(`{"Name":"<b>HTML content</b>"}`))
+       out.WriteTo(os.Stdout)
+       // Output:
+       //{"Name":"\u003cb\u003eHTML content\u003c/b\u003e"}
+}