Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
gojsonschema
✓ github.com/xeipuuv/gojsonschema
Validates a JSON document against a JSON Schema.
package main
import (
"fmt"
"github.com/xeipuuv/gojsonschema"
)
func main() {
schemaLoader := gojsonschema.NewReferenceLoader("file:///path/to/schema.json")
documentLoader := gojsonschema.NewReferenceLoader("file:///path/to/document.json")
result, err := gojsonschema.Validate(schemaLoader, documentLoader)
if err != nil {
panic(err)
}
if result.Valid() {
fmt.Println("The document is valid")
} else {
fmt.Println("The document is not valid. See errors:")
for _, desc := range result.Errors() {
fmt.Printf("- %s\n", desc)
}
}
}
Debug
Known issues
No known issues recorded.
Upgrade
Version history
1.2.0latest on pkg.go.dev
Audit
Dependencies
No dependency data recorded yet.