json-builder-0.0.1: Data structure agnostic JSON serialization

MaintainerLeon P Smith <leon@melding-monads.com>

Data.Json.Builder

Description

Data structure agnostic JSON serialization

Synopsis

Documentation

class Value a => Key a whereSource

The Key typeclass represents types that are rendered into json strings. They are special because only strings can appear as field names of a json objects.

Methods

escape :: a -> EscapedSource

class Value a whereSource

The Value typeclass represents types that can be rendered into valid json syntax.

Methods

toBuilder :: a -> BuilderSource

data Object Source

The Object type represents a builder that constructs syntax for a json object. It has a singleton constructor row, and an instance of monoid, so that arbitrary objects can be constructed. 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.

row :: (Key k, Value a) => k -> a -> ObjectSource

The row constructs a json object consisting of exactly one field. These objects can be concatinated using mappend.

data Array Source

The Array type represents a builder that constructs syntax for a json array. It has a singleton constructor element and an instance of monoid, so that arbitrary arrays can be constructed.

Instances

element :: Value a => a -> ArraySource

The element function constructs a json array consisting of exactly one value. These arrays can be concatinated using mappend.

newtype Escaped Source

The Escaped type is a special Builder value that represents a UTF-8 encoded string with all necessary characters json-escaped. These builders must not render the opening or closing quotes, which are instead rendered by toBuilder. This is so that Json strings can be efficiently constructed from multiple Haskell strings without actually concatinating the Haskell strings (which might require some kind of conversion in addition to concatination.)

Constructors

Escaped Builder