Standard library / encoding/json
encoding/json.Valid()
Report whether bytes form exactly one syntactically valid JSON value. This does not validate application schema or reject duplicate keys. Expected stdout: 'true false\n'.
Formal Syntax & Structure
go syntaxgo
func Valid(data []byte) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| data | []byte | Input bytes to decode. |
Return Value
bool
Whether the stated condition holds.
Working Example
Example Snippetgo
package main
import ( "encoding/json" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { fmt.Println(json.Valid([]byte(`{"x":1}`)), json.Valid([]byte(`{"x":}`))) }