All Projects → santhosh-tekuri → Jsonschema

santhosh-tekuri / Jsonschema

Licence: bsd-3-clause
JSONSchema (draft04, draft06, draft07) Validation using Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Jsonschema

Ajv
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
Stars: ✭ 10,340 (+3861.69%)
Mutual labels:  json-schema, validator
Ajv Keywords
Custom JSON-Schema keywords for Ajv validator
Stars: ✭ 186 (-28.74%)
Mutual labels:  json-schema, validator
Ajv I18n
Internationalised error messages for Ajv JSON-Schema validator
Stars: ✭ 98 (-62.45%)
Mutual labels:  json-schema, validator
Formily
Alibaba Group Unified Form Solution -- Support React/ReactNative/Vue2/Vue3
Stars: ✭ 6,554 (+2411.11%)
Mutual labels:  json-schema, validator
schema
SpaceAPI JSON schema files.
Stars: ✭ 20 (-92.34%)
Mutual labels:  json-schema, validator
Swagger Parser
Swagger 2.0 and OpenAPI 3.0 parser/validator
Stars: ✭ 710 (+172.03%)
Mutual labels:  json-schema, validator
Ajv Errors
Custom error messages in JSON-Schema for Ajv
Stars: ✭ 185 (-29.12%)
Mutual labels:  json-schema, validator
Ajv Cli
Use 'Another Json Validator' (ajv) from the command line
Stars: ✭ 148 (-43.3%)
Mutual labels:  json-schema, validator
finspec-spec
Multi-protocol, machine-readable specifications for financial services
Stars: ✭ 18 (-93.1%)
Mutual labels:  json-schema, validator
another-json-schema
Another JSON Schema validator, simple & flexible & intuitive.
Stars: ✭ 48 (-81.61%)
Mutual labels:  json-schema, validator
Swagger Cli
Swagger 2.0 and OpenAPI 3.0 command-line tool
Stars: ✭ 321 (+22.99%)
Mutual labels:  json-schema, validator
Maat
Validation and transformation library powered by deductive ascending parser. Made to be extended for any kind of project.
Stars: ✭ 27 (-89.66%)
Mutual labels:  json-schema, validator
Djv
Dynamic JSON Schema Validator - Supports draft-04/06
Stars: ✭ 281 (+7.66%)
Mutual labels:  json-schema, validator
Schemasafe
A reasonably safe JSON Schema validator with draft-04/06/07/2019-09 support.
Stars: ✭ 67 (-74.33%)
Mutual labels:  json-schema, validator
Validr
A simple, fast, extensible python library for data validation.
Stars: ✭ 205 (-21.46%)
Mutual labels:  json-schema, validator
openui5-validator
A library to validate OpenUI5 fields
Stars: ✭ 17 (-93.49%)
Mutual labels:  json-schema, validator
ty
Here is a schema checker which can return well typed results. Tell your friends!
Stars: ✭ 21 (-91.95%)
Mutual labels:  json-schema, validator
excel validator
Python script to validate data in Excel files
Stars: ✭ 14 (-94.64%)
Mutual labels:  validator
js-form-validator
Javascript form validation. Pure JS. No jQuery
Stars: ✭ 38 (-85.44%)
Mutual labels:  validator
validation
Validation on Laravel 5.X|6.X|7.X|8.X
Stars: ✭ 26 (-90.04%)
Mutual labels:  validator

jsonschema v3.0.1

License GoDoc Go Report Card Build Status codecov.io

Package jsonschema provides json-schema compilation and validation.

This implementation of JSON Schema, supports draft4, draft6 and draft7.

Passes all tests in https://github.com/json-schema/JSON-Schema-Test-Suite with following exceptions:

  • format idn-hostname and idn-email is not implemented
  • since this library uses regexp package, some optional ECMA-262 related tests will fail
  • in draft4 1.0 is a not a valid integer but in draft6 and draft7 it is valid integer. This library treats 1.0 as integer even in draft4.

For breaking changes from v2 to v3 check github releases page.

An example of using this package:

import "github.com/santhosh-tekuri/jsonschema/v3"

schema, err := jsonschema.Compile("schemas/purchaseOrder.json")
if err != nil {
    return err
}
f, err := os.Open("purchaseOrder.json")
if err != nil {
    return err
}
defer f.Close()
if err = schema.Validate(f); err != nil {
    return err
}

The schema is compiled against the version specified in $schema property. If $schema property is missing, it uses latest draft which currently is draft7. You can force to use draft4 when $schema is missing, as follows:

compiler := jsonschema.NewCompiler()
compler.Draft = jsonschema.Draft4

you can also validate go value using schema.ValidateInterface(interface{}) method.
but the argument should not be user-defined struct.

This package supports loading json-schema from filePath and fileURL.

To load json-schema from HTTPURL, add following import:

import _ "github.com/santhosh-tekuri/jsonschema/v2/httploader"

Loading from urls for other schemes (such as ftp), can be plugged in. see package jsonschema/httploader for an example

To load json-schema from in-memory:

data := `{"type": "string"}`
url := "sch.json"
compiler := jsonschema.NewCompiler()
if err := compiler.AddResource(url, strings.NewReader(data)); err != nil {
    return err
}
schema, err := compiler.Compile(url)
if err != nil {
    return err
}
f, err := os.Open("doc.json")
if err != nil {
    return err
}
defer f.Close()
if err = schema.Validate(f); err != nil {
    return err
}

This package supports json string formats:

  • date-time
  • date
  • time
  • hostname
  • email
  • ip-address
  • ipv4
  • ipv6
  • uri
  • uriref/uri-reference
  • regex
  • format
  • json-pointer
  • relative-json-pointer
  • uri-template (limited validation)

Developers can register their own formats by adding them to jsonschema.Formats map.

"base64" contentEncoding is supported. Custom decoders can be registered by adding them to jsonschema.Decoders map.

"application/json" contentMediaType is supported. Custom mediatypes can be registered by adding them to jsonschema.MediaTypes map.

ValidationError

The ValidationError returned by Validate method contains detailed context to understand why and where the error is.

schema.json:

{
      "$ref": "t.json#/definitions/employee"
}

t.json:

{
    "definitions": {
        "employee": {
            "type": "string"
        }
    }
}

doc.json:

1

Validating doc.json with schema.json, gives following ValidationError:

I[#] S[#] doesn't validate with "schema.json#"
  I[#] S[#/$ref] doesn't valide with "t.json#/definitions/employee"
    I[#] S[#/definitions/employee/type] expected string, but got number

Here I stands for instance document and S stands for schema document.
The json-fragments that caused error in instance and schema documents are represented using json-pointer notation.
Nested causes are printed with indent.

Custom Extensions

Custom Extensions can be registered as shown in extension_test.go

CLI

jv <schema-file> [<json-doc>]...

if no <json-doc> arguments are passed, it simply validates the <schema-file>.

exit-code is 1, if there are any validation errors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].