Giter Site home page Giter Site logo

jordanmartinez / purescript-json-codecs Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 1.0 709 KB

A unidirectional value-based JSON codec library.

License: MIT License

Dhall 3.98% PureScript 69.98% JavaScript 26.03%
codec json purescript decoding encoding

purescript-json-codecs's Introduction

purescript-json-codecs

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

purescript-json-codecs's People

Contributors

jordanmartinez avatar peterbecich avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

peterbecich

purescript-json-codecs's Issues

Figure out best way to add the `Field` hint

Right now, nothing is using the Field hint. Ideally, that would happen with Record, but i'm not yet sure how I want to define this in the code. Perhaps a sum type for each of the cases?

  • NoHint - doesn't add a hint
  • ReuseKeyHint - Reuses the label under which the value is decoded
  • NamedHint - uses the specified label (e.g. if the JSON label doesn't match the end-type's label)

Write documentation

Meaning, documentation comments within the source code itself. The DESIGN.md file already covers the overview of the design.

Topics include:

  • using the pje identity function to remove type variables in records
  • best practices for adding decoding context to bidi codecs
  • ideas for overriding existing error types (e.g. colors used in the AnsiDodoError)

The `fix` function stack overflows

I was writing another benchmark, this time for a recursive data structure. While argonaut-codec (class-based) and codec-argonaut (value-based) worked fine, mine stack overflows.

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.