json-builder-0.3: Data structure agnostic JSON serialization

Copyright(c) 2011-2012 Leon P Smith
LicenseBSD3
MaintainerLeon P Smith <leon@melding-monads.com>
Safe HaskellNone
LanguageHaskell98

Data.Json.Builder.Internal

Description

Internal bits. By using the constructors provided in this module, you can break the abstraction that json-builder provides and emit invalid JSON syntax. Also, this module is not as stable as the public interface and can change at any time.

Synopsis

Documentation

newtype Json #

The Json type represents valid json syntax. It cannot be directly analyzed, however it can be turned into a Builder via toBuilder, a (lazy) ByteString via toJsonBS or toJsonLBS, or used as a component of a json Array or json Object using element or row.

Constructors

Json Builder 

Instances

Value Json # 

Methods

toJson :: Json -> Json #

newtype Object #

The Object type represents syntax for a json object. It has a singleton constructor row, and an instance of Monoid, so that mempty represents the empty object and mappend concatinates two objects. Arbitrary objects can be constructed using these operators.

Note that duplicate field names will appear in the output, so it is up to the user of this interface to avoid duplicate field names.

Constructors

Object CommaMonoid 

Instances

newtype Array #

The Array type represents syntax for a json array. It has been given a singleton constructor element and an instance of Monoid, so that mempty represents the empty array and mappend concatinates two arrays. Arbitrary arrays can be constructed using these operators.

Constructors

Array CommaMonoid 

Instances

Monoid Array # 

Methods

mempty :: Array #

mappend :: Array -> Array -> Array #

mconcat :: [Array] -> Array #

JsArray Array # 

Methods

toArray :: Array -> Array #

Value Array # 

Methods

toJson :: Array -> Json #

newtype Escaped #

The Escaped type represents json string syntax. The purpose of this type is so that json strings can be efficiently constructed from multiple Haskell strings without superfluous conversions or concatinations.

Internally, it is just a Builder value which must produce a UTF-8 encoded bytestring with backslashes, quotes, and control characters appropriately escaped. It also must not render the opening or closing quote, which are instead rendered by toJson.

Constructors

Escaped Builder 

data CommaMonoid #

A CommaMonoid inserts commas between builders. In order to satisify the Monoid identity laws, Empty must be distinguished from Comma mempty. To demonstrate the difference:

mconcat ["foo", ""    , "bar"]  ==  "foo,,bar"
mconcat ["foo", Empty , "bar"]  ==  "foo,bar"

The strings in this example denote CommaMonoids via fromString = Comma . fromString. Thus "" is equivalent to Comma mempty.

Constructors

Empty 
Comma !Builder