Text.JSONb.Schema
- data Schema counter
- schema :: Counter counter => JSON -> Schema counter
- props :: Counter counter => Trie JSON -> Props counter
- schemas :: Counter counter => [JSON] -> [(counter, Schema counter)]
- collate :: (Counter counter, Counter counter') => (counter, Schema counter') -> [(counter, Schema counter')] -> [(counter, Schema counter')]
- data Props counter = Props (Trie (Set (Schema counter)))
- merge :: Counter counter => Props counter -> Props counter -> Props counter
- match :: Counter counter => Props counter -> Props counter -> Bool
- data Elements counter = Elements [(counter, Schema counter)]
- data OneMany
- class (Eq t, Show t, Ord t) => Counter t where
Documentation
The type of JSON schemas. We treat the atomic types simply whereas objects and arrays are treated specially.
Objects are treated as maps of keys to sets of schema types. Say a certain type of object sometimes has a string at a certain key and sometimes has a null at that key; we should merge them and say the schema of that key is a union of string and null.
Arrays admit measure in the sense of how many elements there are of a certain kind. We support three measures at present: any, one or more and individual counts. We expect the any measure to prevail practice. Arrays are also ordered; so one can distinguish an array that interleaves strings and ints from one that is all strings and then all ints.
schemas :: Counter counter => [JSON] -> [(counter, Schema counter)]Source
Develop a schema for a list of JSON data, collating schemas according to the measure, a well-ordered semigroup.
collate :: (Counter counter, Counter counter') => (counter, Schema counter') -> [(counter, Schema counter')] -> [(counter, Schema counter')]Source
Collate a list of counted schemas. Alike counted schemas that are adjacent
are replaced by a counted schema with an incremented counter. This
operation is mutually recursive with merge
, in order to merge comaptible
object definitions before collating.
class (Eq t, Show t, Ord t) => Counter t whereSource
A well-ordered semigroup has a minimal element and an associative
operation. These are used to provide measures for schema. At present, we
allow three measures: whether there is one or more of a schema (measured
with '()'), whether there is one or more than one of an item (measured with
OneMany
) and positive counts of items (measured with Word
).