json-tools / json-schema / Json.Schema

This library provides bunch of utility methods to work with JSON values using schemas defined in JSON Schema format.

Currently it allows to construct schemata (draft-6), validate values and generate random values based on schema (very experimental feature). It supports local references, but doesn't support remote references.

Decode schema

Use fromValue or fromString methods if you receive schema from external source. If you want to construct schema from elm code you might want to use Json.Schema.Builder, or low-level API using definitions from Json.Schema.Definitions

fromValue : Json.Decode.Value -> Result String Definitions.Schema

Construct JSON Schema from JSON value

fromString : String -> Result String Definitions.Schema

Construct JSON Schema from string

Validation

validateValue : ValidationOptions -> Json.Decode.Value -> Definitions.Schema -> Result (List Validation.Error) Json.Decode.Value

Validate value against JSON Schema. Returns Result with updated value in case if validationOptions require so.

schema
    |> Json.Schema.validateValue { applyDefaults = True } value

validateAt : ValidationOptions -> Json.Decode.Value -> Definitions.Schema -> String -> Result (List Validation.Error) Json.Decode.Value

Validate value using subschema identified by URI.