aeson-pretty 0.8.4 → 0.8.5
raw patch · 3 files changed
+14/−10 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Aeson.Encode.Pretty: [confTrailingNewline] :: Config -> Bool
- Data.Aeson.Encode.Pretty: Config :: Indent -> (Text -> Text -> Ordering) -> NumberFormat -> Config
+ Data.Aeson.Encode.Pretty: Config :: Indent -> (Text -> Text -> Ordering) -> NumberFormat -> Bool -> Config
Files
- Data/Aeson/Encode/Pretty.hs +9/−6
- aeson-pretty.cabal +1/−1
- cli-tool/Main.hs +4/−3
Data/Aeson/Encode/Pretty.hs view
@@ -105,6 +105,8 @@ , confCompare :: Text -> Text -> Ordering -- ^ Function used to sort keys in objects , confNumFormat :: NumberFormat+ , confTrailingNewline :: Bool+ -- ^ Whether to add a trailing newline to the output } -- |Sort keys by their order of appearance in the argument list.@@ -118,12 +120,12 @@ -- |The default configuration: indent by four spaces per level of nesting, do--- not sort objects by key.+-- not sort objects by key, do not add trailing newline. ----- > defConfig = Config { confIndent = Spaces 4, confCompare = mempty, confNumFormat = Generic }+-- > defConfig = Config { confIndent = Spaces 4, confCompare = mempty, confNumFormat = Generic, confTrailingNewline = False } defConfig :: Config defConfig =- Config {confIndent = Spaces 4, confCompare = mempty, confNumFormat = Generic}+ Config {confIndent = Spaces 4, confCompare = mempty, confNumFormat = Generic, confTrailingNewline = False} -- |A drop-in replacement for aeson's 'Aeson.encode' function, producing -- JSON-ByteStrings for human readers.@@ -147,7 +149,7 @@ -- |A variant of 'encodeToTextBuilder' that takes an additional configuration -- parameter. encodePrettyToTextBuilder' :: ToJSON a => Config -> a -> Builder-encodePrettyToTextBuilder' Config{..} = fromValue st . toJSON+encodePrettyToTextBuilder' Config{..} x = fromValue st (toJSON x) <> trail where st = PState 0 indent newline itemSep kvSep confNumFormat sortFn indent = case confIndent of@@ -161,10 +163,11 @@ Spaces 0 -> ":" _ -> ": " sortFn = sortBy (confCompare `on` fst)+ trail = if confTrailingNewline then "\n" else "" fromValue :: PState -> Value -> Builder-fromValue st@PState{..} = go+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))@@ -186,7 +189,7 @@ items' = mconcat . intersperse (pItemSep <> pNewline) $ map (\item -> fromIndent st' <> fromItem st' item) items- st' = st { pLevel = pLevel + 1 }+ st' = st { pLevel = pLevel + 1} fromPair :: PState -> (Text, Value) -> Builder fromPair st (k,v) =
aeson-pretty.cabal view
@@ -1,5 +1,5 @@ name: aeson-pretty-version: 0.8.4+version: 0.8.5 license: BSD3 license-file: LICENSE category: Text, Web, JSON, Pretty Printer
cli-tool/Main.hs view
@@ -44,9 +44,10 @@ main :: IO () main = do Opts{..} <- cmdArgs opts- let conf = Config { confIndent = Spaces indent- , confCompare = if sort then compare else mempty- , confNumFormat = Generic+ let conf = Config { confIndent = Spaces indent+ , confCompare = if sort then compare else mempty+ , confNumFormat = Generic+ , confTrailingNewline = False } enc = if compact then encode else encodePretty' conf interact $ unlines . map enc . values