packages feed

json-builder 0.1.1 → 0.2.0

raw patch · 2 files changed

+28/−11 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Json.Builder: toJsonByteString :: Value a => a -> ByteString
- Data.Json.Builder: toJsonLazyByteString :: Value a => a -> ByteString
+ Data.Json.Builder: class JsArray a
+ Data.Json.Builder: class JsObject a
+ Data.Json.Builder: instance [incoherent] (JsString k, Value a) => JsObject (HashMap k a)
+ Data.Json.Builder: instance [incoherent] (JsString k, Value a) => JsObject (Map k a)
+ Data.Json.Builder: instance [incoherent] Value a => JsArray [a]
+ Data.Json.Builder: toArray :: JsArray a => a -> Array
+ Data.Json.Builder: toJsonBS :: Value a => a -> ByteString
+ Data.Json.Builder: toJsonLBS :: Value a => a -> ByteString
+ Data.Json.Builder: toObject :: JsObject a => a -> Object

Files

json-builder.cabal view
@@ -1,5 +1,5 @@ Name:                json-builder-Version:             0.1.1+Version:             0.2.0 Synopsis:            Data structure agnostic JSON serialization License:             BSD3 License-file:        LICENSE@@ -44,4 +44,4 @@ source-repository this   type:     git   location: http://github.com/lpsmith/json-builder-  tag:      v0.1.1+  tag:      v0.2.0
src/Data/Json/Builder.hs view
@@ -20,14 +20,16 @@      ( Value(toJson)      , Json      , toBuilder-     , toJsonByteString-     , toJsonLazyByteString+     , toJsonBS+     , toJsonLBS      , Array      , element      , Object      , row      , JsString(escape)      , Escaped+     , JsArray(toArray)+     , JsObject(toObject)      ) where  import           Prelude hiding ((++))@@ -73,17 +75,23 @@ (++) = mappend infixr 5 ++ +class JsObject a where+  toObject :: a -> Object++class JsArray a where+  toArray  :: a -> Array+ toBuilder :: Value a => a -> Builder toBuilder x = case toJson x of                 Json y -> y {-# SPECIALIZE toBuilder :: Json -> Builder #-} {-# INLINE toBuilder #-} -toJsonByteString     :: Value a => a -> BS.ByteString-toJsonByteString     = toByteString     . toBuilder+toJsonBS  :: Value a => a -> BS.ByteString+toJsonBS  = toByteString     . toBuilder -toJsonLazyByteString :: Value a => a -> BL.ByteString-toJsonLazyByteString = toLazyByteString . toBuilder+toJsonLBS :: Value a => a -> BL.ByteString+toJsonLBS = toLazyByteString . toBuilder  -- |  The 'row' function constructs a json object consisting of exactly -- one field.  These objects can be concatinated using 'mappend'.@@ -209,15 +217,24 @@  -- | renders as an 'Array' instance Value a => Value [a] where-  toJson = toJson . mconcat . map element+  toJson = toJson . toArray +instance Value a => JsArray [a] where+  toArray = foldr (\a as -> element a ++ as) mempty+ -- | renders as an 'Object' instance (JsString k, Value a) => Value (Map.Map k a) where-  toJson = toJson . Map.foldrWithKey     (\k a b -> row k a ++ b) mempty+  toJson = toJson . toObject +instance (JsString k, Value a) => JsObject (Map.Map k a) where+  toObject = Map.foldrWithKey     (\k a b -> row k a ++ b) mempty+ -- | renders as an 'Object' instance (JsString k, Value a) => Value (HashMap.HashMap k a) where-  toJson = toJson . HashMap.foldrWithKey (\k a b -> row k a ++ b) mempty+  toJson = toJson . toObject++instance (JsString k, Value a) => JsObject (HashMap.HashMap k a) where+  toObject = HashMap.foldrWithKey (\k a b -> row k a ++ b) mempty  ------------------------------------------------------------------------------