Code Monkey home page Code Monkey logo

json-schema's Introduction

JSON Schema Validation

A JSON schema validator that builds on the JSON implementation found in fost-base and is built for use in Fostgres. It is implemented in modern C++, specifically C++17.

Assertions

The specifications for them are taken from JSON Schema Validation: A Vocabulary for Structural Validation of JSON (draft 1). All of described assertions are implemented:

  • allOf, anyOf and oneOf -- Values must conform to a specific number of the provided schemas.
  • const -- Values must be equal to the one in the schema.
  • contains -- At least one value in an array conforms to the schema.
  • dependencies -- Object property checks depending on which exist in the data.
  • enum -- Values must be in the specified set.
  • if, then and else -- conditional evaluation of schemas.
  • items and additionalItems-- Array items must confirm to the provided schemas.
  • maximum, minimum, exclusiveMaximum, exlusiveMinimum, multipleOf -- Value bounds checks for numeric data.
  • maxItems and minItems -- bounds for the number of items in a JSON array.
  • maxLength and minLength -- bounds for the number of code points in a string value.
  • maxProperties and minProperties -- counts for properties in a JSON object.
  • not -- negates the contained check.
  • pattern -- The regex must be found in a string value.
  • properties, patternProperties and additionalProperties -- that the assertions for each property hold if present in the JSON object data.
  • propertyNames -- names of object properties must conform to the provided schema.
  • required -- Object properties must include the specified strings.
  • type -- type check against the JSON types (null, boolean, object, array, number, string and integer).
  • uniqueItems -- All values in an array are unique.

The schema used for testing is http://json-schema.org/draft-07/schema#.

Notes

For type validation, if the underlying memory type is a double then it will only match against number even if there is no fractional part to the number. The JSON parser will correctly identify integers parsing JSON (and use the int64_t memory type for them), so this can only happen when JSON is produced by code that uses a double. The memory type int64_t will match both of the number and integer validation types.

The handling of $id is particularly nasty. Although this implementation passes the test suite there are a large number of edge cases with the interactions between $ref and $id that are not tested or covered. Our recommendation is to avoid use of $id except for a full URL at schema root if required.

The JSON Schema Testsuite

The build target json-schema-testsuite will download and run the tests that are found at the JSON Schema Test Suite.

json-schema's People

Contributors

kayess avatar tleekkul avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.