JSON Schema for Go
package schema_test
import (
"log"
"github.com/lestrrat/go-jsschema"
"github.com/lestrrat/go-jsschema/validator"
)
func Example() {
s, err := schema.ReadFile("schema.json")
if err != nil {
log.Printf("failed to read schema: %s", err)
return
}
for name, pdef := range s.Properties {
// Do what you will with `pdef`, which contain
// Schema information for `name` property
_ = name
_ = pdef
}
// You can also validate an arbitrary piece of data
var p interface{} // initialize using json.Unmarshal...
v := validator.New(s)
if err := v.Validate(p); err != nil {
log.Printf("failed to validate data: %s", err)
}
}
- Properly resolve ids and $refs (it works in simple cases, but elaborate scopes probably don't work)
Name | Notes |
---|---|
go-jsval | Validator generator |
go-jshschema | JSON Hyper Schema implementation |
go-jsref | JSON Reference implementation |
go-jspointer | JSON Pointer implementations |