json-schema

Types and type classes for defining JSON schemas.

Version on this page:0.7.4.0@rev:4
LTS Haskell 12.26:0.7.4.2@rev:1
Stackage Nightly 2018-09-28:0.7.4.2
Latest on Hackage:0.7.4.2@rev:1

See all snapshots json-schema appears in

BSD-3-Clause licensed by Silk
Maintained by [email protected]
This version can be pinned in stack with:json-schema-0.7.4.0@sha256:beff777d3390f1f927cf650ae4231f13e8f1d93fa5505fe7e8d337e356bd71b1,2309

json-schema

Build Status

json-schema is like XML schemas, but for JSON. It’s haskell specific and has no relation to json-schema.org.

The package provides

  • An AST type Schema defining the structure of a JSON object.
  • A type class JSONSchema to define a schema for a type.
  • Combinators for defining schemas.
  • A module for validating Aeson values against schemas.
  • Built-in instances matching aeson’s.
  • A Generics module matching aeson instances generated by generics-aeson

If you use another library for generating JSON instances (such as aeson’s built-in generics/template haskell) or write aeson instances by hand you will not get matching JSONSchema instances if you use json-schema’s generics module.

This package assumes that your ToJSON and FromJSON instances match.

Installation

This package is available on hackage

$ cabal install json-schema

Examples

see the examples folder or The test suite.

Changes

Changelog

0.7.4.0

  • Raise upper length limit of UTCTime since aeson-0.9 increased the precision.
  • Add JSONSchema Aeson.Value instance.

0.7.3.7

  • Allow generic-deriving 1.8.*
  • Allow vector 0.11.*

0.7.3.6

  • Allow aeson 0.9.*

0.7.3.5

  • Allow attoparsec 0.13.*

0.7.3.4

  • Fix compilation on GHC 7.2 and 7.4

0.7.3.3

  • Allow tagged 0.8.* in test-suite

0.7.3.2

  • Allow tagged 0.8.*

0.7.3.1

  • test-suite: Allow aeson-utils 0.3.*

0.7.3.0

  • Add JSONSchema instances for all standard Num types and Scientific.

0.7.2.0

  • Add JSONSchema instances for Double, Float, Fixed

0.7.1.1

  • Allow generic-deriving 1.7.*

0.7.1.0

  • Export GJSONSchema type to allow clients to write type signatures for gSchema and gSchemaWithSettings.

0.7.0.2

  • Allow time 1.5.*

0.7.0.1

  • Drop support for old tasty versions

0.7.0.0

  • Removed the Null constructor from Schema, use Data.JSON.Schema.Combinators.nullable instead.

  • Added the Validation module that can be used to validate a json object against a schema and to get descriptive error messages.

  • Updates for Maybe fixes in generic-aeson 0.2.0.0 including more thorough test cases.

0.6.1.1

  • Bugfix: Remove underscores from fields and constructors in generated schemas to match generic-aeson.

0.6.1

  • Add JSONSchema instances for tuples up to length 15 (matching aeson 0.8 instances)
  • Specify uniqueness for JSONSchema instances for Set.

0.6

Breaking changes:

  • Add Constant Aeson.Value type to Schema
  • Change Number to take a Bound for the boundary. Before this the upper bound could not be -1.
  • Change Value and Array to take a LengthBound. The difference from Number is that these values should always be >= 0 if present.

Minor:

  • Add Bound { lower :: Maybe Int, upper :: Maybe Int }
  • Add unbounded as a shorthand for a Bound without restrictions
  • Add LengthBound { lowerLength :: Maybe Int, upperLength :: Maybe Int }
  • Add unboundedLength as a shorthand for a LengthBound without restrictions
  • Add remaining JSONSchema instances based on existing Aeson instances. UTCTime, Set, Lazy Text, and tuples up to length 7.
  • Add enum combinator as a shorthand for creating a Choice of Constants

0.5

  • JSONSchema instances for Data.Vector, Data.Map, and Data.HashMap
  • Add Map type for json objects with arbitrary keys
  • Add Any type for any json value
  • Don’t generate empty field names in ojbects for constructors without labeled fields