Skip to content

JSON Schema Draft 4 validator implementation. Powered by go-faster/jx.

License

Notifications You must be signed in to change notification settings

tdakkota/jsonschema

Repository files navigation

jsonschema

Go Reference codecov

jsonschema is a JSON Schema Draft 4 validator implementation

Usage

package example

import (
	"fmt"

	"github.com/tdakkota/jsonschema"
)

func Example() {
	schema, err := jsonschema.Parse([]byte(`{
      "type": "object",
      "properties": {
        "number": { "type": "number" },
        "street_name": { "type": "string" },
        "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
      }
    }`))
	if err != nil {
		panic(err)
	}

	if err := schema.Validate(
		[]byte(`{ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" }`),
	); err != nil {
		panic(err)
	}

	fmt.Println(schema.Validate([]byte(`{"number": "1600"}`)))
	// Output:
	// object: "number": string: type is not allowed
}

Install

go get -d github.com/tdakkota/jsonschema

Roadmap

See this issue.

About

JSON Schema Draft 4 validator implementation. Powered by go-faster/jx.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages