Skip to content

Commit

Permalink
encoding/json: add example to Valid
Browse files Browse the repository at this point in the history
Change-Id: I411483d76a2ca91cd15ff42ae1adb9134486d183
Reviewed-on: https://go-review.googlesource.com/c/145278
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
hearot authored and bradfitz committed Oct 28, 2018
1 parent 3bab437 commit 3fe9d4c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/encoding/json/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,12 @@ func ExampleMarshalIndent() {
// <prefix><indent>"b": 2
// <prefix>}
}

func ExampleValid() {
goodJSON := `{"example": 1}`
badJSON := `{"example":2:]}}`

fmt.Println(json.Valid([]byte(goodJSON)), json.Valid([]byte(badJSON)))
// Output:
// true false
}

0 comments on commit 3fe9d4c

Please sign in to comment.