JSONb-1.0.8: JSON parser that uses byte strings.

Safe HaskellSafe-Infered

Text.JSONb

Description

ByteString parser for a simple, monomorphic JSON datatype.

Synopsis

Documentation

data JSON Source

A monomorphic JSON datatype, backed with Rational, strict ByteString and ByteString Trie.

Instances

decode :: ByteString -> Either String JSONSource

Interpret a ByteString as any JSON literal.

break :: ByteString -> (Either String JSON, ByteString)Source

Split out the first parseable JSON literal from the input, returning the result of the attempt along with the remainder of the input or the whole input if no parseable item was discovered.

data Style Source

Style of serialization. Compact is the only one that is implemented at present.

Constructors

Compact 

Instances

encode :: Style -> JSON -> ByteStringSource

Encode JSON as a strict ByteString. All strings are treated as UTF-8; ASCII control characters are escaped and UTF-8 multi-char sequences are simply passed through.

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.

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.

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.

class Display t whereSource

Methods

bytes :: t -> ByteStringSource

Provide a formatted ByteString for the displayable.

Instances

Display Word 
Display () 
Display OneMany 
Display counter => Display (Schema counter) 
Display counter => Display (counter, Schema counter) 

class Escape t whereSource

Class of JSON escapable text. The solidus (/) is always escaped, as are all ASCII control characters. Non-ASCII control characters and Unicode printable characters above ASCII are left as is.

Methods

escape :: t -> tSource