Package

purescript-json-codecs

Repository
jordanmartinez/purescript-json-codecs
License
MIT
Uploaded by
pacchettibotti
Published on
2023-10-09T19:55:32Z

A unidirectional value-based JSON codec library.

Whether this is more performant than other options is still being clarified. See the benchmarks.

Design

See DESIGN.md for the reasoning behind this library's design. The rest of this section covers my goals and where I'm at in that process.

Address gripes with other JSON codec libraries:

  • simple-json:
    • I don't want to have to fork or copy the repo to benefit from it / change various type class instances.
    • I don't want to use your information-poor error type, NonEmptyList ForeignError
  • argonaut-codec/codec-argonaut:
    • I don't want to use your "does not allow custom error messages" type, JsonDecodeError
    • Allow me to specify the order in which to encode something
    • Allow me the ability to rename fields when encoding/decoding

Improve error messages:

  • on type mismatch errors, show me what you expected AND got, not just what was expected
  • allow me to write custom error messages

Provide record syntax that distinguishes between

  • when decoding
    • optional fields: whether a field is required or optional
    • renaming: decoding a key "foo" but putting it in a record label "bar"
  • when encoding
    • order of fields: the order in which to encode fields
    • renaming: encoding a record label "bar" but encoding it as "foo" in the JSON
  • See snapshots

For an example of decoding text and encoding examples, see ./test/test-output.txt

License

Modules
Codec.Json.Unidirectional.Value
Codec.Json.Unidirectional.Value.SortRowList
Dependencies