-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Data structure agnostic JSON serialization -- -- Most json packages dictate a data structure that corresponds to json -- values. To serialize other values to json, then that value must be -- marshalled into the specified structure. -- -- This library avoids this marshalling step, and is thus potentially -- more efficient when serializing arbitrary data structures. -- Unfortunately json-builder cannot yet read or process json data, and -- it's not clear to me yet how pull a similar kind of trick to avoid -- unnecessary data structures when parsing json data into arbitrary data -- types. @package json-builder @version 0.2.0 -- | Internal bits. You can break this library's abstraction and emit -- invalid Json syntax the constructors provided in this module. module Data.Json.Builder.Internal -- | The Value typeclass represents types that can be rendered into -- valid json syntax. class Value a toJson :: Value a => a -> Json -- | The Json type represents valid json syntax. It cannot be -- directly analyzed, however it can be rendered into a ByteString -- and used to as a component of an array or an object to build a bigger -- json value. newtype Json Json :: Builder -> Json -- | The String typeclass represents types that render into json -- string syntax. They are special because only strings can appear as -- field names of json objects. class Value a => JsString a escape :: JsString a => a -> 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. newtype Escaped Escaped :: Builder -> Escaped -- | 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. newtype Object Object :: CommaMonoid -> Object -- | 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. newtype Array Array :: CommaMonoid -> Array data CommaMonoid Empty :: CommaMonoid Comma :: !Builder -> CommaMonoid instance Monoid Escaped instance Monoid Array instance Monoid Object instance Monoid CommaMonoid instance Value Array instance Value Object instance JsString Escaped instance Value Escaped instance Value Json -- | Data structure agnostic JSON serialization module Data.Json.Builder -- | The Value typeclass represents types that can be rendered into -- valid json syntax. class Value a toJson :: Value a => a -> Json -- | The Json type represents valid json syntax. It cannot be -- directly analyzed, however it can be rendered into a ByteString -- and used to as a component of an array or an object to build a bigger -- json value. data Json toBuilder :: Value a => a -> Builder toJsonBS :: Value a => a -> ByteString toJsonLBS :: Value a => a -> ByteString -- | 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. data Array -- | The element function constructs a json array consisting of -- exactly one value. These arrays can be concatinated using -- mappend. element :: Value a => a -> Array -- | 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. data Object -- | The row function constructs a json object consisting of exactly -- one field. These objects can be concatinated using mappend. row :: (JsString k, Value a) => k -> a -> Object -- | The String typeclass represents types that render into json -- string syntax. They are special because only strings can appear as -- field names of json objects. class Value a => JsString a escape :: JsString a => a -> 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. data Escaped class JsArray a toArray :: JsArray a => a -> Array class JsObject a toObject :: JsObject a => a -> Object instance [incoherent] (JsString k, Value a) => JsObject (HashMap k a) instance [incoherent] (JsString k, Value a) => Value (HashMap k a) instance [incoherent] (JsString k, Value a) => JsObject (Map k a) instance [incoherent] (JsString k, Value a) => Value (Map k a) instance [incoherent] Value a => JsArray [a] instance [incoherent] Value a => Value [a] instance [incoherent] Value [Char] instance [incoherent] JsString [Char] instance [incoherent] Value Text instance [incoherent] JsString Text instance [incoherent] Value Text instance [incoherent] JsString Text instance [incoherent] Value ByteString instance [incoherent] JsString ByteString instance [incoherent] Value ByteString instance [incoherent] JsString ByteString instance [incoherent] Value Bool instance [incoherent] Value Float instance [incoherent] Value Double instance [incoherent] Value Word64 instance [incoherent] Value Word32 instance [incoherent] Value Word16 instance [incoherent] Value Word8 instance [incoherent] Value Word instance [incoherent] Value Integer instance [incoherent] Value Int64 instance [incoherent] Value Int32 instance [incoherent] Value Int16 instance [incoherent] Value Int8 instance [incoherent] Value Int instance [incoherent] Value ()