diff --git a/hledger-lib/Hledger/Utils/Text.hs b/hledger-lib/Hledger/Utils/Text.hs index cabe127a1..c4bf0b393 100644 --- a/hledger-lib/Hledger/Utils/Text.hs +++ b/hledger-lib/Hledger/Utils/Text.hs @@ -26,6 +26,7 @@ module Hledger.Utils.Text stripquotes, -- isSingleQuoted, -- isDoubleQuoted, + jsonPrettyText, -- -- * single-line layout textstrip, textlstrip, @@ -59,6 +60,8 @@ module Hledger.Utils.Text ) where +import Data.Aeson (Value) +import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder) -- import Data.Char import Data.List #if !(MIN_VERSION_base(4,11,0)) @@ -66,6 +69,8 @@ import Data.Monoid #endif import Data.Text (Text) import qualified Data.Text as T +import qualified Data.Text.Lazy as TL +import Data.Text.Lazy.Builder (toLazyText) -- import Text.Parsec -- import Text.Printf (printf) @@ -78,6 +83,10 @@ import Hledger.Utils.Test -- lowercase = map toLower -- uppercase = map toUpper +-- | Pretty-print a JSON value. +jsonPrettyText :: Value -> TL.Text +jsonPrettyText = toLazyText . encodePrettyToTextBuilder + -- | Remove leading and trailing whitespace. textstrip :: Text -> Text textstrip = textlstrip . textrstrip diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 1e0fc15ea..26591681e 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -4,7 +4,7 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -- --- hash: f5d891a2f435cece44dd66f1ca32e8e55fde986a4129a443d3de60ab6f65b5e3 +-- hash: d8c943c6b632e6b0cf34a564809ef96869541c54de93613e7103ec87fadb4e33 name: hledger-lib version: 1.17.99 @@ -111,6 +111,7 @@ library Decimal >=0.5.1 , Glob >=0.9 , aeson + , aeson-pretty , ansi-terminal >=0.6.2.3 , array , base >=4.9 && <4.15 @@ -162,6 +163,7 @@ test-suite doctest Decimal >=0.5.1 , Glob >=0.7 , aeson + , aeson-pretty , ansi-terminal >=0.6.2.3 , array , base >=4.9 && <4.15 @@ -216,6 +218,7 @@ test-suite unittest Decimal >=0.5.1 , Glob >=0.9 , aeson + , aeson-pretty , ansi-terminal >=0.6.2.3 , array , base >=4.9 && <4.15 diff --git a/hledger-lib/package.yaml b/hledger-lib/package.yaml index 3f4822cee..7da186bd6 100644 --- a/hledger-lib/package.yaml +++ b/hledger-lib/package.yaml @@ -47,6 +47,7 @@ dependencies: - base >=4.9 && <4.15 - base-compat-batteries >=0.10.1 && <0.12 - aeson +- aeson-pretty - ansi-terminal >=0.6.2.3 - array - blaze-markup >=0.5.1