Skip to content

An implementation of JSON Schema, draft v4 - Go language

Notifications You must be signed in to change notification settings

mattlandis/gojsonschema

This branch is 273 commits behind xeipuuv/gojsonschema:master.

Folders and files

NameName
Last commit message
Last commit date
Sep 4, 2013
Sep 13, 2013
Sep 5, 2013
Sep 5, 2013
Sep 5, 2013
Jun 22, 2013
Jun 25, 2013
Jun 18, 2013
Sep 6, 2013
Sep 5, 2013
Sep 9, 2013
Jul 5, 2013

Repository files navigation

gojsonschema

Description

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

Status

Functional, one feature is missing : id(s) as scope for references

Test phase : Passed 99.59% of Json Schema Test Suite

Usage

Basic example


package main

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

func main() {

    // use a remote schema
    schema, err := gojsonschema.NewJsonSchemaDocument("http://myhost/schema1.json")
    // ... or a local file
    //schema, err := gojsonschema.NewJsonSchemaDocument("file:///home/me/myschemas/schema1.json")
    if err != nil {
        panic(err.Error())
    }

    // use a remote json to validate
    jsonToValidate, err := gojsonschema.GetHttpJson("http://myhost/someDoc1.json")
    // ... or a local one
    //jsonToValidate, err := gojsonschema.GetFileJson("/home/me/mydata/someDoc1.json")

    if err != nil {
        panic(err.Error())
    }

    validationResult := schema.Validate(jsonToValidate)

    if validationResult.IsValid() {

        fmt.Printf("The document is valid\n")

    } else {

        fmt.Printf("The document is not valid. see errors :\n")
        for _, errorMessage := range validationResult.GetErrorMessages() {
            fmt.Printf("- %s\n", errorMessage)
        }

    }

}


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

About

An implementation of JSON Schema, draft v4 - Go language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published