added cyclic reference detection, fixed pointer and reference
interaction to pass the reference encoding tests
6 files changed
tree: 988acba454b9907b07ef85a4e1bda7b7a1a066de
  1. json_schema_test_suite/
  2. README.md
  3. schema.go
  4. schema_test.go
  5. schemaDocument.go
  6. schemaPool.go
  7. schemaType.go
  8. types.go
  9. validation.go
  10. validationutil.go
README.md

gojsonschema

Description

An implementation of JSON Schema, based on IETF's draft v4 - Go language

Status

Working, but not all keyword are yet implemented.

What is missing : definitions, dependencies

Testing / debugging / improvements in progress ( Passed 91% of Json Schema Test Suite )

Usage

Basic example

package main 

import (
	"github.com/sigu-399/gojsonschema"
	"fmt"
)

func main() {

	schema, err := gojsonschema.NewJsonSchemaDocument("http://myhost/bla/schema1.json")
	// OR
	//schema, err := gojsonschema.NewJsonSchemaDocument("file:///home/me/myschemas/schema1.json")
	
	if err != nil {
		panic(err.Error())
	}

	jsonToValidate, err := gojsonschema.GetHttpJson("http://myotherhost/blu/extract56.json")
	// OR
	//jsonToValidate, err := gojsonschema.GetFileJson("file:///home/billy/hotels.json")
	
	if err != nil {
		panic(err.Error())
	}

	validationResult := schema.Validate(jsonToValidate)

	fmt.Printf("IsValid %v\n", validationResult.IsValid())
	fmt.Printf("%v\n", validationResult.GetErrorMessages())

}

References

###Website http://json-schema.org

###Schema Core http://json-schema.org/latest/json-schema-core.html

###Schema Validation http://json-schema.org/latest/json-schema-validation.html

Dependencies

https://github.com/sigu-399/gojsonpointer

https://github.com/sigu-399/gojsonreference

Uses

gojsonschema uses the following test suite :

https://github.com/json-schema/JSON-Schema-Test-Suite