jsons-to-schema: JSON to JSON Schema

[ data, json, library, mit, program, web ] [ Propose Tags ] [ Report a vulnerability ]

A JSON Schema Draft 4 Generator from JSON Instances


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0
Dependencies aeson (>=0.11.3.0 && <1.2), aeson-pretty (>=0.7.2 && <0.9), base (>=4.7 && <5), bytestring (>=0.10.6.0 && <0.11), conduit (>=1.2.10 && <1.3), conduit-combinators (>=1.0.8.3 && <1.2), containers (>=0.5.6.2 && <0.6), Glob (>=0.7.14 && <0.9), hjsonschema (>=1.6.3 && <1.7), jsons-to-schema, optparse-applicative (>=0.12.1.0 && <0.14), protolude (>=0.1.10 && <0.2), QuickCheck (>=2.8.2 && <2.10), safe (>=0.3.14 && <0.4), scientific (>=0.3.4.9 && <0.4), semigroups (>=0.18.2 && <0.19), text (>=1.2.2.2 && <1.3), unordered-containers (>=0.2.8.0 && <0.3), vector (>=0.11.0.0 && <0.13) [details]
Tested with ghc ==7.10.3, ghc ==8.0.2
License MIT
Copyright 2017 Gareth Tan
Author Gareth Tan
Maintainer Gareth Tan
Category Data, Web, JSON
Home page https://github.com/garetht/jsons-to-schema/README.md
Source repo head: git clone https://github.com/garetht/jsons-to-schema
Uploaded by garetht at 2017-07-30T16:09:12Z
Distributions
Executables jsons-to-schema-exe
Downloads 1008 total (4 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-07-30 [all 1 reports]

Readme for jsons-to-schema-0.1.0.0

[back to package description]

JSONs to Schema

A JSON Schema Draft 4 Generator from JSON Instances

Suppose you have an API that produces complex and somewhat varied JSON. You'd like to be able to document that API in a standard format by observing only its output. JSON Schema is a reasonable format for that. But simply generating the schema for one document will lead to an incomplete description of the API since not all documents will have all the keys in the full document. This is where this library comes in.

CLI Overview

JSONs to Schema can also be used on the command line. After locating the installed binary, run it with --help to get detailed usage instructions.

API Overview

The main API function is jsonsToSchema along with its configuration-taking equivalent, jsonsToSchemaWithConfig. This will transform a set of JSON documents into a single Maybe schema.

Other helpful functions are jsonToSchema, which transforms a single document, and schemasToSchema, which performs the actual work of schema unification.

Properties

The schema generator should satisfy these properties:

  • An schema generated from a JSON document will always be able to validate that JSON document.
  • When a schema is merged with another schema, all objects that would validate under either schema, subject to the assumptions below, will validate under the merged schema regardless of merge order.

Unlike other generators strictness is meant to be customizable. Whether to allow additional properties in schema objects is something that the user can turn on and off.

Assumptions

When merging JSON documents the generator keeps track of only one possible underlying type for each primitive type. Thus, if there were two documents {"name": "x"} and {"cost": 24} they will be assumed to represent two different manifestations of a single document that has both the name and the cost keys, rather than two different documents.

If given an object and an array (or some other primitive type), however, the generator will be able to assume that the particular JSON document can be either an object or an array type.

Prior Art

This project was inspired by GenSON, a Python project that does much of the same, but aims to be more customizable, correct, and powerful.

Certain features were also inspired by schema-guru, but this project aims to be more customizable and have a programmatic API. Schema Guru's enum and range detection features are planned to be matched by this library.

Future Plans

  • Option to autogenerate enumerations for fields with below a certain limit of values
  • Option to automatically detect ranges for integers, strings, arrays, and objects

Not Planned

  • Recognition of known JSON Schema formats (UUIDs and IP addresses, for example)
  • Support for JSON or JSON Schema extensions