category feedJSONPopular data formatseditdelete







JSON is a very popular format that is used pretty much everywhere. It looks like this:

{
    "name": "John Smith",
    "isAlive": true,
    "age": 25,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021-3100" },
    "phoneNumbers": [
        { "type": "home",
          "number": "212 555-1234" },
        { "type": "mobile",
          "number": "123 456-7890" } ]
}

It supports objects (dictionaries), arrays, strings, numbers, booleans, and null. JSON doesn't distinguish between integers and floating-point numbers, and doesn't provide any way to handle binary data.

Recommendations

Everyone uses aeson. All other libraries are either outdated or experimental.

You might have to use one of the alternative encoders if you really need performance and Aeson isn't enough for you, or you might have to use one of the alternative decoders if you really need constant-space decoding, but those are rare cases.

Aeson doesn't provide pretty-printed JSON out of the box, so use aeson-pretty for that.

TODO

Benchmark various encoders/decoders. Give examples for everything.

Not included

  • easyjson: seems to provide the same parsing model as aeson, has no extra functionality, and only works with base-4.7

  • json-ast: could be useful for some purposes (it's a tiny library providing just the JSON type, nothing else), but hard to categorise here

edit description
or press Ctrl+Enter to savemarkdown supported
#
aeson (Hackage)
encoder/decoder
move item up move item down edit item info delete item
Summary edit summary

Haskell's de-facto standard JSON parsing library.

Summary quit editing summary
Prosedit prosquit editing pros
  • Widely used and actively developed.
    move trait up move trait down edit trait delete trait
  • Fast.
    move trait up move trait down edit trait delete trait

press Ctrl+Enter or Enter to addmarkdown supportededit off
Consedit consquit editing cons
  • Can be rather complicated/non-intuitive to use.
    move trait up move trait down edit trait delete trait

press Ctrl+Enter or Enter to addmarkdown supportededit off
Ecosystemedit ecosystem
Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
#
encoder/decoder
move item up move item down edit item info delete item
Summary edit summary

Flexible, precise, and efficient JSON decoding/encoding library. This package provides a plethora of tools for decoding, encoding, and manipulating JSON data.

Summary quit editing summary
Prosedit prosquit editing pros
  • Fully RFC compliant
    move trait up move trait down edit trait delete trait
  • Encoders and Decoders are values, they are not tied to a typeclass and as such you are not tied to a single interpretation of how a particular type "should" be handled
    move trait up move trait down edit trait delete trait
  • No information is discarded on parsing
    move trait up move trait down edit trait delete trait

press Ctrl+Enter or Enter to addmarkdown supportededit off
Consedit consquit editing cons
  • Requires slightly more code than automatically derived typeclass based approaches
    move trait up move trait down edit trait delete trait

press Ctrl+Enter or Enter to addmarkdown supportededit off
Ecosystemedit ecosystem
Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
Notes
collapse notesedit notes

<notes are empty>

add something!

#
highjson (Hackage)
encoder/decoder
move item up move item down edit item info delete item
Summary edit summary

A fast library that tries to require less boilerplate than aeson (and provides a different parsing model). Use at your own risk.

Summary quit editing summary
Prosedit prosquit editing pros
  • As fast as Aeson (benchmarks).
    move trait up move trait down edit trait delete trait
  • The same declaration is used to convert to/from JSON – there's no need to write separate ToJSON and FromJSON instances and worry about them accidentally going out of sync.
    move trait up move trait down edit trait delete trait

press Ctrl+Enter or Enter to addmarkdown supportededit off
Consedit consquit editing cons
  • The library is still work in progress.
    move trait up move trait down edit trait delete trait
  • There are some examples, but not much documentation.
    move trait up move trait down edit trait delete trait

press Ctrl+Enter or Enter to addmarkdown supportededit off
Ecosystemedit ecosystem
Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
Notes
collapse notesedit notes

<notes are empty>

add something!

#
json-encoder (Hackage)
encoder
move item up move item down edit item info delete item
Summary edit summary

A fast JSON builder.

Summary quit editing summary
Prosedit prosquit editing pros

    press Ctrl+Enter or Enter to addmarkdown supportededit off
    Consedit consquit editing cons

      press Ctrl+Enter or Enter to addmarkdown supportededit off
      Ecosystemedit ecosystem
      Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
      Notes
      collapse notesedit notes

      <notes are empty>

      add something!

      #
      buffer-builder (Hackage)
      encoder
      move item up move item down edit item info delete item
      Summary edit summary

      Another fast JSON builder.

      Summary quit editing summary
      Prosedit prosquit editing pros

        press Ctrl+Enter or Enter to addmarkdown supportededit off
        Consedit consquit editing cons

          press Ctrl+Enter or Enter to addmarkdown supportededit off
          Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
          Notes
          collapse notesedit notes

          <notes are empty>

          add something!

          #
          json-stream (Hackage)
          decoder
          move item up move item down edit item info delete item
          Summary edit summary

          A fast decoder that tries to do the least amount of work possible (e.g. it skips parsing of unnecessary fields, etc) and can even parse certain JSON structures using constant space.

          Summary quit editing summary
          Prosedit prosquit editing pros
          • Compatible with aeson.
            move trait up move trait down edit trait delete trait

          press Ctrl+Enter or Enter to addmarkdown supportededit off
          Consedit consquit editing cons
          • Sometimes doesn't tell you when the JSON is malformed (this is by design, tho).
            move trait up move trait down edit trait delete trait

          press Ctrl+Enter or Enter to addmarkdown supportededit off
          Ecosystemedit ecosystem
          Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
          Notes
          collapse notesedit notes

          <notes are empty>

          add something!

          #
          json-incremental-decoder (Hackage)
          decoder
          move item up move item down edit item info delete item
          Summary edit summary

          Another incremental decoder.

          Summary quit editing summary
          Prosedit prosquit editing pros

            press Ctrl+Enter or Enter to addmarkdown supportededit off
            Consedit consquit editing cons

              press Ctrl+Enter or Enter to addmarkdown supportededit off
              Ecosystemedit ecosystem
              Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
              Notes
              collapse notesedit notes

              <notes are empty>

              add something!

              #
              aeson-parsec-picky (Hackage)
              decoder
              move item up move item down edit item info delete item
              Summary edit summary

              A JSON parser written in Parsec, can be used instead of the default Aeson parser. Intended for use with human-written JSON (config files, etc) – unlike Aeson's parser, it reports error positions, which is pretty useful.

              Summary quit editing summary
              Prosedit prosquit editing pros
              • Compatible with aeson.
                move trait up move trait down edit trait delete trait

              press Ctrl+Enter or Enter to addmarkdown supportededit off
              Consedit consquit editing cons
              • Slower than the default aeson parser.
                move trait up move trait down edit trait delete trait
              • Disallows trailing spaces, which isn't good if you simply wanted a parser that would be the same as Aeson's parser but with better error reporting.
                move trait up move trait down edit trait delete trait

              press Ctrl+Enter or Enter to addmarkdown supportededit off
              Ecosystemedit ecosystem
              Ecosystemquit editing ecosystemor press Ctrl+Enter to savemarkdown supported
              Notes
              collapse notesedit notes

              <notes are empty>

              add something!