Skip to content
Newer
Older
100644 23 lines (13 sloc) 1.96 KB
7178b68 @lpsmith Change module name
authored Jun 2, 2011
1 `json-builder` is a data structure agnostic json serialization library. Most existing serializers operate on a specific data structure that corresponds to a json value. Other pieces of data must then marshaled into that data structure before they can be serialized to json.
afe63ee @lpsmith Add README.markdown
authored Jun 2, 2011
2
7178b68 @lpsmith Change module name
authored Jun 3, 2011
3 `json-builder` avoids this marshaling, and thus is potentially more efficient when you want to serialize arbitrary data structures. Moreover, I've found that writing a serializer using this API to be somewhat simpler than writing a marshaller into the data structures used by the [json](http://hackage.haskell.org/package/json) or [aeson](http://hackage.haskell.org/package/aeson) packages.
afe63ee @lpsmith Add README.markdown
authored Jun 2, 2011
4
7178b68 @lpsmith Change module name
authored Jun 3, 2011
5 Unfortunately, `json-builder` cannot yet read or process json data. Moreover, it's not clear to me how to pull a similar kind of trick above, and avoid unnecessary data structures.
afe63ee @lpsmith Add README.markdown
authored Jun 2, 2011
6
936b473 @lpsmith Bring the README up to date, somewhat
authored Jun 4, 2011
7 This library revolves around a single typeclass `Value` that represents pieces of data that can be serialized to the Json format. It's member is `toJson`, which returns a newtyped [Builder](http://hackage.haskell.org/packages/archive/blaze-builder/0.3.0.1/doc/html/Blaze-ByteString-Builder.html) that represents the concrete syntax of that value.
afe63ee @lpsmith Add README.markdown
authored Jun 2, 2011
8
936b473 @lpsmith Bring the README up to date, somewhat
authored Jun 4, 2011
9 class Value a where
10 toJson :: a -> Json
afe63ee @lpsmith Add README.markdown
authored Jun 2, 2011
11
b361f12 @lpsmith Improve README.markdown
authored Jun 2, 2011
12 Arrays are represented by an abstract type with a singleton constructor `element` and a [monoid](http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.1.0/Data-Monoid.html#t:Monoid) instance. Thus arbitrary sequences can be serialized using `mempty` and `mappend`.
13
14 element :: Value a => a -> Array
15 instance Monoid Array
16
936b473 @lpsmith Bring the README up to date, somewhat
authored Jun 4, 2011
17 Objects are similar. There is a typeclass `JsString` that distinguishes strings from other Json values, a singleton constructor, and a monoid instance. Note that rows with duplicate keys will appear in the output; it is up to the user of this interface to ensure that keys are unique.
b361f12 @lpsmith Improve README.markdown
authored Jun 2, 2011
18
936b473 @lpsmith Bring the README up to date, somewhat
authored Jun 4, 2011
19 class Value a => JsString a
b361f12 @lpsmith Improve README.markdown
authored Jun 2, 2011
20
936b473 @lpsmith Bring the README up to date, somewhat
authored Jun 4, 2011
21 row :: (JsString a, Value b) => a -> b -> Object
b361f12 @lpsmith Improve README.markdown
authored Jun 2, 2011
22 instance Monoid Object
Something went wrong with that request. Please try again.