Valid in Go

Posted by GoDoc
Public (Editable by Users)

Valid reports whether data is a valid JSON encoding.

Go
Edit
package main

import (
	"encoding/json"
	"fmt"
)

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

	fmt.Println(json.Valid([]byte(goodJSON)), json.Valid([]byte(badJSON)))
}