aeson-pretty 0.4.0 → 0.5.0
raw patch · 2 files changed
+25/−33 lines, 2 filesdep −blaze-builderdep ~aesondep ~vectorPVP ok
version bump matches the API change (PVP)
Dependencies removed: blaze-builder
Dependency ranges changed: aeson, vector
API changes (from Hackage documentation)
Files
- Data/Aeson/Encode/Pretty.hs +20/−25
- aeson-pretty.cabal +5/−8
Data/Aeson/Encode/Pretty.hs view
@@ -3,8 +3,6 @@ -- |Aeson-compatible pretty-printing of JSON 'Value's. module Data.Aeson.Encode.Pretty (encodePretty) where -import Blaze.ByteString.Builder (Builder, toLazyByteString, fromByteString)-import Blaze.ByteString.Builder.Char.Utf8 (fromChar) import Data.Aeson (Value(..), ToJSON(..)) import qualified Data.Aeson.Encode as Aeson import Data.ByteString.Lazy (ByteString)@@ -12,6 +10,8 @@ import Data.List (intersperse) import Data.Monoid (mappend, mconcat, mempty) import Data.Text (Text)+import Data.Text.Lazy.Builder (Builder, toLazyText)+import Data.Text.Lazy.Encoding (encodeUtf8) import qualified Data.Vector as V (toList) @@ -20,41 +20,36 @@ -- |A drop-in replacement for aeson's 'Aeson.encode' function, producing -- JSON-ByteStrings for human readers. encodePretty :: ToJSON a => a -> ByteString-encodePretty = toLazyByteString . fromValue 0 . toJSON+encodePretty = encodeUtf8 . toLazyText . fromValue 0 . toJSON fromValue :: Indent -> Value -> Builder fromValue ind = go where- go (Array v) = fromCompound ind ('[',']') fromValue (V.toList v)- go (Object m) = fromCompound ind ('{','}') fromPair (H.toList m)+ go (Array v) = fromCompound ind ("[","]") fromValue (V.toList v)+ go (Object m) = fromCompound ind ("{","}") fromPair (H.toList m) go v = Aeson.fromValue v fromCompound :: Indent- -> (Char, Char)+ -> (Builder, Builder) -> (Indent -> a -> Builder) -> [a] -> Builder-fromCompound ind (delimL,delimR) fromItem items = - fromChar delimL `mappend` items' `mappend` fromChar delimR+fromCompound ind (delimL,delimR) fromItem items =+ delimL <>+ if null items then mempty+ else "\n" <> items' <> "\n" <> fromIndent ind <>+ delimR where- newLine = fromChar '\n'- items' = if null items then mempty- else mconcat- [ newLine- , mconcat . intersperse (fromChar ',' `mappend` newLine) $- map (\i -> fromIndent (ind+1) `mappend`- fromItem (ind+1) i)- items- , newLine- , fromIndent ind- ]+ items' = mconcat . intersperse ",\n" $+ map (\item -> fromIndent (ind+1) <> fromItem (ind+1) item)+ items fromPair :: Indent -> (Text, Value) -> Builder-fromPair ind (k,v) =- mconcat [ Aeson.fromValue (toJSON k)- , fromByteString ": "- , fromValue ind v- ]+fromPair ind (k,v) = Aeson.fromValue (toJSON k) <> ": " <> fromValue ind v fromIndent :: Indent -> Builder-fromIndent ind = mconcat $ replicate (ind*4) $ fromChar ' '+fromIndent ind = mconcat $ replicate (ind*4) " "++(<>) :: Builder -> Builder -> Builder+(<>) = mappend+infixr 6 <>
aeson-pretty.cabal view
@@ -1,5 +1,5 @@ name: aeson-pretty-version: 0.4.0+version: 0.5.0 license: BSD3 license-file: LICENSE category: Text, Web, JSON, Pretty Printer@@ -7,7 +7,6 @@ author: Falko Peters <falko.peters@gmail.com> maintainer: Falko Peters <falko.peters@gmail.com> stability: experimental-tested-with: GHC == 6.12.3 cabal-version: >= 1.8 homepage: http://github.com/informatikr/aeson-pretty bug-reports: http://github.com/informatikr/aeson-pretty/issues@@ -43,14 +42,13 @@ buildable: False else build-depends:- aeson == 0.4.0.*,+ aeson == 0.5.0.*, attoparsec == 0.10.*, base == 4.*,- blaze-builder == 0.3.*, bytestring == 0.9.*, cmdargs == 0.7.*, containers,- vector == 0.9,+ vector == 0.9.*, text == 0.11.*, unordered-containers >= 0.1.3.0 @@ -62,13 +60,12 @@ Data.Aeson.Encode.Pretty build-depends:- aeson == 0.4.0.*,+ aeson == 0.5.0.*, attoparsec == 0.10.*, base == 4.*,- blaze-builder == 0.3.*, bytestring == 0.9.*, containers,- vector == 0.9,+ vector == 0.9.*, text == 0.11.*, unordered-containers >= 0.1.3.0