Giter VIP home page Giter VIP logo

aeson-pretty's People

Contributors

9999years avatar chrismwendt avatar dougburke avatar hasufell avatar informatikr avatar ion1 avatar jkarni avatar koterpillar avatar ksromanov avatar leftaroundabout avatar martijnbastiaan avatar phadej avatar ulfsauer0815 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aeson-pretty's Issues

`prettyprinter` support?

I have been looking for a Value prettyprinter that produces a prettyprinter Doc. aeson-pretty doesn't, but perhaps it's something it could do?

encodePretty doesn't respect omitNothingFields option

data Item =
  Item
    { code:: String
    , thumbUrl :: Maybe T.Text
    }
  deriving (Generic, Show, Eq, Ord)

instance ToJSON Item where
    toEncoding = genericToEncoding defaultOptions
      { omitNothingFields = True }

instance Item Game where
  parseJSON = genericParseJSON defaultOptions { omitNothingFields = True}

encodePretty [ Item {code= "foo", thumbUrl = Nothing}]

Expected output:
"[\n {\n "code": "foo"\n }\n]"
Actual output:
"[\n {\n "thumbUrl": null,\n "code": "foo"\n }\n]"

Doesn't build with aeson >=2

haskell/aeson#864

$ cabal repl --build-depends aeson-pretty                                                                                                             Sat 21:12
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - aeson-pretty-0.8.8 (lib) (requires build)
 - fake-package-0 (lib) (first run)
Starting     aeson-pretty-0.8.8 (lib)
Building     aeson-pretty-0.8.8 (lib)

Failed to build aeson-pretty-0.8.8.
Build log (
/home/hasufell/.cabal/logs/ghc-8.10.7/aeson-pretty-0.8.8-7d5e0bebeaf77dbf14fbe263246433acbce057be5e13a95f8a842096920829bb.log
):
Configuring library for aeson-pretty-0.8.8..
Preprocessing library for aeson-pretty-0.8.8..
Building library for aeson-pretty-0.8.8..
[1 of 1] Compiling Data.Aeson.Encode.Pretty ( Data/Aeson/Encode/Pretty.hs, dist/build/Data/Aeson/Encode/Pretty.o, dist/build/Data/Aeson/Encode/Pretty.dyn_o )

Data/Aeson/Encode/Pretty.hs:58:1: error:
    Could not load module ‘Data.Aeson.Encode’
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘aeson-1.5.6.0’.
    Perhaps you need to add ‘aeson’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
   |
58 | import qualified Data.Aeson.Encode as Aeson
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Failed to build aeson-pretty-0.8.8 (which is required by
fake-package-0). See the build log above for details.

strange type of encodePretty function

Hello. I just installed your library via cabal install aeson-pretty. Then I tried to use it and found strange signature:

encodePretty :: aeson-0.7.0.0:Data.Aeson.Types.Class.ToJSON a => a -> Data.ByteString.Lazy.Internal.ByteString

Why the type constraint is aeson-0.7.0.0:Data.Aeson.Types.Class.ToJSON a and not ToJSON a? Have I installed it wrong?

Aeson.toEncoding method implementations not respected

It doesn't appear that encodePretty or any of the other variants of that function respect custom encoding options defined in toEncoding.

Small example:

data Person = Person 
    { _name :: Text
    , _age  :: Int
    } deriving (Generic, Show)

instance ToJSON Blockchain where
    toEncoding = genericToEncoding $ defaultOptions { fieldLabelModifier = stripUnderscorePrefix }
      where stripUnderscorePrefix = ...

Using encode on this data type, I correctly get {"name": ..., "age": ...}. But using encodePretty instead gives me {"_name": ..., "_age": ...}.

I think this is because the underlying encodePrettyToTextBuilder' calls toJSON directly, which does not apply the encoding options. If possible, it'd be great to preserve the options when using encodePretty.

expose text builder

It would be nice if you could expose a lazy text builder a la

Data.Aeson.Encode.encodeToTextBuilder

but with pretty-printing support. Something like

encodeToTextBuilder :: Config -> Value -> Builder
encodeToTextBuilder Config{..} = toLazyText . fromValue st
  where
    st       = PState confIndent 0 condSort
    condSort = sortBy (confCompare `on` fst)

[Install cmd tool] command not found error

I have cabal version 1.22.6.0 and I installed aeson-pretty-0.7.2

when I write :

=>cabal install aeson-pretty
Resolving dependencies...
All the requested packages are already installed:
aeson-pretty-0.7.2

Use --reinstall if you want to reinstall anyway.

but when I run aeson-pretty I get zsh: command not found: aeson-pretty

I tried to follow the instructions for installation but I couldn't run it anyway from the terminal

My OSX version: 10.11.4

Again incorrect scientific formatting.

Would you please revert #19 . The reason - scientific package has updated, now it formats everything like it was proposed:

     Generic ->
      doFmt (if e < 0 || e > 7 then Exponent else Fixed)
            (is,e)

Aeson 1.2.1, instead, does not check for large numbers (with exponent higher than 7):

fromScientific :: Scientific -> Builder
fromScientific s = formatScientificBuilder format prec s
  where
    (format, prec)
      | base10Exponent s < 0 = (Generic, Nothing)
      | otherwise            = (Fixed,   Just 0)

So, currently we have output:

"intBillion" : 1000000000

If you do not want to output trailing .0, you need to make a special formatter:

prettyFormatter :: S.Scientific -> Builder
prettyFormatter n
    | S.isFloating n == True = formatScientificBuilder S.Generic Nothing n
    | otherwise =formatScientificBuilder S.Generic (Just 0) n -- output no digits after decimal point

This will output

"double0" : 0,
"doubleHalf" : 0.5,
"intTwo" : 2,
"intMillion" : 1000000
"intBillion" : 1.0e9

Support for YAML like formatting

instead of

{
    "name": "John Doe",
    "country": "Germany",
    "favorite_color": "green"
}

format it as

name: John Doe
country: Germany
favorite_color: green

Single-line output

Feature request: I'd like to be able to encode JSON with spaces but without line breaks.

For example, let x = Array (fromList [Number 1, Number 2]).

  • encode x produces "[1,2]"
  • encodePretty x produces "[\n 1,\n 2\n]"
  • What I'd like is "[1, 2]"

Trailing newline option

A viable use case for pretty printing is outputting a JSON value to console or a file, and in both cases a trailing newline is desirable.

Updates for the latest version of aeson

Installing aeson-pretty-0.7.1 together with aeson-0.7.0.6 gives this compilation error:

    In the use of ‘Aeson.fromValue’ (imported from Data.Aeson.Encode):
    Deprecated: "Use 'encodeToTextBuilder' instead"
In-place registering aeson-pretty-0.7.1...
Preprocessing executable 'aeson-pretty' for aeson-pretty-0.7.1...
[1 of 2] Compiling Paths_aeson_pretty ( dist/dist-sandbox-75adb5f/build/autogen/Paths_aeson_pretty.hs, dist/dist-sandbox-75adb5f/build/aeson-pretty/aeson-pretty-tmp/Paths_aeson_pretty.o )
[2 of 2] Compiling Main             ( cli-tool/Main.hs, dist/dist-sandbox-75adb5f/build/aeson-pretty/aeson-pretty-tmp/Main.o )
Failed to load interface for ‘Data.Aeson.Encode.ByteString’
There are files missing in the ‘aeson-0.7.0.6’ package,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.