Skip to content

JSON schema validator for Python. Modified fork of fastjsonschema.

License

Notifications You must be signed in to change notification settings

RowAnalytics/precisionlife_fastjsonschema

 
 

Repository files navigation

Modified fast JSON schema for Python

This is a modification of fastjsonschema done for the following purposes:

  • Add support for validating documents that are composed from any Sequences and Mappings, not only lists and dicts.
  • Include full path to validated field in error messages. (see: horejsek#63)
  • Improve error messages for anyOf and oneOf rules by:
    • introducing concept of "discriminator fields",
    • if object is a Mapping, and has any of the discriminator fields, then it is assumed it must match first schema that does not return any error on any of the discriminator fields,
    • introducing concept of "tag fields",
    • if object is a Mapping, and has any of the tag fields, then it is assumed it must match first schema that allows this field to exist,
    • if object is a Mapping, and has any tag or discriminator fields, and failed validation, then an error is returned that says those tag/discriminator fields have invalid values, all more specific errors are dropped. (see: horejsek#72)
  • introducing concept of "identification fields", values of those fields, for every object on the path to the root, will be printed when reporting errors, this way it will be easier to identify which object failed validation, especially within large arrays.
  • When unexpected additional fields are present those should be enumerated in error message. (see: horejsek#84)
  • Make the store for cached documents overridable.
  • Improve handling of custom network schemes in $ref links.
  • Added special hacky internal-no-cache scheme that prevents from caching a schema.

Please note that tag and discriminator fields must be hand-picked for any given schema, as there is no logic that automatically figures them out. Also if those fields are specified incorrectly some correct documents might be rejected.

About tag and discriminator fields

Existence of a tag field on an object determines which schema out of anyOf or oneOf should be chosen. Existence of a discriminator field with a specific value determines which schema out of anyOf or oneOf should be chosen.

Example where 'type' is a discriminator field. From the value of this field we know which schema must be used. :

{
   type: square
   width: 5
}
{
   type: circle
   radius: 5
}

Example where '$add' and '$log' are tag fields. From existence of any of those fields we know which schema must be used. :

{
   $add: 5
   other: 2
}
{
   $log: 3
   base: 10
}

Status of original fastjsonschema package

PyPI version Supported Python versions

See documentation.

About

JSON schema validator for Python. Modified fork of fastjsonschema.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.6%
  • Makefile 1.4%