aeson-pretty 0.8.7 → 0.8.11
raw patch · 5 files changed
Files
- CHANGELOG.markdown +12/−0
- Data/Aeson/Encode/Pretty.hs +23/−8
- README.markdown +4/−3
- aeson-pretty.cabal +18/−19
- cli-tool/Main.hs +12/−3
+ CHANGELOG.markdown view
@@ -0,0 +1,12 @@+# aeson-pretty changelog++## 0.8.11+ * Dropped support for Aeson 1.4 and older+ * Added support for Aeson 2.3+ * Added support for Aeson 2.2++## 0.8.10+ * Added support for Aeson 2.1++## 0.8.9+ * Added support for Aeson 2.0
Data/Aeson/Encode/Pretty.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE OverloadedStrings, RecordWildCards #-}+{-# LANGUAGE OverloadedStrings, RecordWildCards, CPP #-} -- |Aeson-compatible pretty-printing of JSON 'Value's. module Data.Aeson.Encode.Pretty (@@ -54,14 +54,22 @@ keyOrder ) where +#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.Key as AK+import qualified Data.Aeson.KeyMap as AKM+#endif import Data.Aeson (Value(..), ToJSON(..))-import qualified Data.Aeson.Encode as Aeson+import qualified Data.Aeson.Text as Aeson import Data.ByteString.Lazy (ByteString) import Data.Function (on)+#if !MIN_VERSION_aeson(2,0,0) import qualified Data.HashMap.Strict as H (toList)+#endif import Data.List (intersperse, sortBy, elemIndex) import Data.Maybe (fromMaybe)+#if !MIN_VERSION_base(4,13,0) import Data.Semigroup ((<>))+#endif import qualified Data.Scientific as S (Scientific, FPFormat(..)) import Data.Ord (comparing) import Data.Text (Text)@@ -87,10 +95,11 @@ data Indent = Spaces Int | Tab data NumberFormat- -- | The standard behaviour of the 'Aeson.encode' function. Uses- -- integer literals for integers (1, 2, 3...), simple decimals- -- for fractional values between 0.1 and 9,999,999, and scientific- -- notation otherwise.+ -- | For numbers with absolute value less than 1e19, this follows the standard+ -- behaviour of the 'Data.Aeson.encode' function. Uses integer literals for+ -- integers (1, 2, 3...), simple decimals for fractional values between 0.1+ -- and 9,999,999, and scientific notation otherwise. For numbers with an+ -- absolute value larger than 1e19, always uses scientific notation. = Generic -- | Scientific notation (e.g. 2.3e123). | Scientific@@ -146,7 +155,7 @@ encodePrettyToTextBuilder :: ToJSON a => a -> Builder encodePrettyToTextBuilder = encodePrettyToTextBuilder' defConfig --- |A variant of 'encodeToTextBuilder' that takes an additional configuration+-- |A variant of 'Aeson.encodeToTextBuilder' that takes an additional configuration -- parameter. encodePrettyToTextBuilder' :: ToJSON a => Config -> a -> Builder encodePrettyToTextBuilder' Config{..} x = fromValue st (toJSON x) <> trail@@ -170,9 +179,15 @@ fromValue st@PState{..} val = go val where go (Array v) = fromCompound st ("[","]") fromValue (V.toList v)- go (Object m) = fromCompound st ("{","}") fromPair (pSort (H.toList m))+ go (Object m) = fromCompound st ("{","}") fromPair (pSort (toList' m)) go (Number x) = fromNumber st x go v = Aeson.encodeToTextBuilder v++#if MIN_VERSION_aeson(2,0,0)+ toList' = fmap (\(k, v) -> (AK.toText k, v)) . AKM.toList+#else+ toList' = H.toList+#endif fromCompound :: PState -> (Builder, Builder)
README.markdown view
@@ -1,7 +1,5 @@ # Welcome to aeson-pretty -[](https://travis-ci.org/informatikr/aeson-pretty)- This is a JSON pretty-printing Haskell library compatible with [aeson](http://hackage.haskell.org/package/aeson) as well as a command-line tool to improve readabilty of streams of JSON data. The **library** provides a single function `encodePretty`. It is a drop-in replacement for aeson's `encode` function, producing JSON-ByteStrings for human readers.@@ -20,6 +18,9 @@ * `git clone git://github.com/informatikr/aeson-pretty.git` +# Aeson / GHC support+We support all GHCs supported by the latest Aeson release. This in turn determines which Aeson releases we support.+ # Authors -This library is written and maintained by Falko Peters, <falko.peters@gmail.com>.+This library is written by Falko Peters <falko.peters@gmail.com> and maintained by Martijn Bastiaan <martijn@qbaylogic.com>.
aeson-pretty.cabal view
@@ -1,20 +1,20 @@+cabal-version: 2.0 name: aeson-pretty-version: 0.8.7+version: 0.8.11 license: BSD3 license-file: LICENSE category: Text, Web, JSON, Pretty Printer copyright: Copyright 2011 Falko Peters author: Falko Peters <falko.peters@gmail.com>-maintainer: Falko Peters <falko.peters@gmail.com>+maintainer: Martijn Bastiaan <martijn@hmbastiaan.nl> stability: experimental-cabal-version: >= 1.8 homepage: http://github.com/informatikr/aeson-pretty bug-reports: http://github.com/informatikr/aeson-pretty/issues build-type: Simple synopsis: JSON pretty-printing library and command-line tool. description: A JSON pretty-printing library compatible with aeson as well as- a command-line tool to improve readabilty of streams of JSON data.+ a command-line tool to improve readability of streams of JSON data. . The /library/ provides the function "encodePretty". It is a drop-in replacement for aeson's "encode" function, producing JSON-ByteStrings for@@ -22,43 +22,41 @@ . The /command-line tool/ reads JSON from stdin and writes prettified JSON to stdout. It also offers a complementary "compact"-mode, essentially the- opposite of pretty-printing. If you specify @-flib-only@ like this- .- > cabal install -flib-only aeson-pretty- .- the command-line tool will NOT be installed.+ opposite of pretty-printing. extra-source-files: README.markdown +extra-doc-files:+ CHANGELOG.markdown+ flag lib-only description: Only build/install the library, NOT the command-line tool. default: False+ manual: True library exposed-modules: Data.Aeson.Encode.Pretty build-depends:- aeson >= 0.7,- base >= 4.5,- base-compat >= 0.9 && < 0.11,+ aeson >=1.5 && <2.4,+ base >= 4.10 && < 4.23,+ base-compat >= 0.9, bytestring >= 0.9, scientific >= 0.3, vector >= 0.9, text >= 0.11,- unordered-containers >= 0.1.3.0-- if !impl(ghc >= 8.0)- build-depends:- semigroups >= 0.18.2+ unordered-containers >= 0.2.14.0 ghc-options: -Wall+ default-language: Haskell2010 executable aeson-pretty hs-source-dirs: cli-tool main-is: Main.hs other-modules: Paths_aeson_pretty+ autogen-modules: Paths_aeson_pretty if flag(lib-only) buildable: False@@ -67,12 +65,13 @@ aeson >= 0.6, aeson-pretty, attoparsec >= 0.10,- base == 4.*,+ attoparsec-aeson,+ base >= 4.10 && < 4.23, bytestring >= 0.9, cmdargs >= 0.7 ghc-options: -Wall- ghc-prof-options: -auto-all+ default-language: Haskell2010 source-repository head type: git
cli-tool/Main.hs view
@@ -1,9 +1,14 @@-{-# LANGUAGE DeriveDataTypeable, RecordWildCards, OverloadedStrings #-}+{-# LANGUAGE CPP, DeriveDataTypeable, RecordWildCards, OverloadedStrings, PackageImports #-} module Main (main) where import Prelude hiding (interact, concat, unlines, null)-import Data.Aeson (Value(..), json', encode)+import Data.Aeson (Value(..), encode) import Data.Aeson.Encode.Pretty+#if MIN_VERSION_aeson(2,2,0)+import "attoparsec-aeson" Data.Aeson.Parser.Internal (value')+#else+import "aeson" Data.Aeson.Parser.Internal (value')+#endif import Data.Attoparsec.Lazy (Result(..), parse) import Data.ByteString.Lazy.Char8 (ByteString, interact, unlines, null) import Data.Version (showVersion)@@ -15,7 +20,11 @@ , indent :: Int , sort :: Bool }+#if __GLASGOW_HASKELL__ >= 912+ deriving (Data)+#else deriving (Data, Typeable)+#endif opts :: Options opts = Opts@@ -53,7 +62,7 @@ interact $ unlines . map enc . values values :: ByteString -> [Value]-values s = case parse json' s of+values s = case parse value' s of Done rest v -> v : values rest Fail rest _ _ | null rest -> []