Skip to content

Latest commit

 

History

History
53 lines (40 loc) · 1.2 KB

README.md

File metadata and controls

53 lines (40 loc) · 1.2 KB

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.