JSONb-1.0.1: JSON parser that uses byte strings.

Text.JSONb.Schema

Synopsis

Documentation

data Schema counter Source

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.

Constructors

Num 
Str 
Bool 
Null 
Obj (Props counter) 
Arr (Elements counter) 

Instances

Eq counter => Eq (Schema counter) 
Ord counter => Ord (Schema counter) 
Display counter => Show (Schema counter) 
Display counter => Display (Schema counter) 
Display counter => Display (counter, Schema counter) 

schema :: Counter counter => JSON -> Schema counterSource

Determine a schema for one JSON data item.

props :: Counter counter => Trie JSON -> Props counterSource

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.

data Props counter Source

Constructors

Props (Trie (Set (Schema counter))) 

Instances

Eq counter => Eq (Props counter) 
Ord counter => Ord (Props counter) 

merge :: Counter counter => Props counter -> Props counter -> Props counterSource

Merge two property sets. This operation is mutually recursive with our collate and relies on polymorphic recusion in collate.

match :: Counter counter => Props counter -> Props counter -> BoolSource

data Elements counter Source

Constructors

Elements [(counter, Schema counter)] 

Instances

Eq counter => Eq (Elements counter) 
Ord counter => Ord (Elements counter) 

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).

Methods

bottom :: tSource

plus :: t -> t -> tSource