GithubHelp home page GithubHelp logo

state-machine-systems / jsoncodec Goto Github PK

View Code? Open in Web Editor NEW
38.0 4.0 7.0 53 KB

JSON combinator library for BuckleScript/Reason

License: Apache License 2.0

OCaml 19.14% JavaScript 1.01% C++ 79.84%
json reason reasonml bucklescript picklers combinator

jsoncodec's People

Contributors

dratini0 avatar ebuall avatar glennsl avatar idkjs avatar johnwright 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

Watchers

 avatar  avatar  avatar  avatar

jsoncodec's Issues

Recursive codecs

Add fixpoint and/or lazy combinators to allow recursive structures.

HOWTO decode into records?

Just some nice examples in the README.md would go a long way.

Love the idea of this library by the way ❤️.

One thing I was hoping to find: How do you convert a some JSON into a record? In Elm you would use something like: http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Json-Decode#map or perhaps http://package.elm-lang.org/packages/NoRedInk/elm-decode-pipeline/latest

Example in Elm using elm-decode-pipeline

import Json.Decode exposing (int, string, float, Decoder)
import Json.Decode.Pipeline exposing (decode, required, optional, hardcoded)

-- basically a record in Elm
type alias User =
  { id : Int
  , email : Maybe String
  , name : String
  , percentExcited : Float
  }


userDecoder : Decoder User
userDecoder =
  decode User
    |> required "id" int
    |> required "email" (nullable string) -- `null` decodes to `Nothing`
    |> optional "name" string "(fallback if name is `null` or not present)"
    |> hardcoded 1.0

Question: tradeoffs?

Hello @johnwright. This JSON library looks interesting! I'll read its paper, but I was wondering about its tradeoffs too (perf, size, theoretical blockers, etc.)?

The idea of having a free decoder from an encoder or vice-versa sounds pretty attractive, and if possible, I'd like the official Reason one to be free of ppx (which is needed mostly because of the usual encoding/decoding boilerplate).

Arrays as tuples

It's common in JSON to use arrays as tuples, e.g.

{
  "pairs": [
    [1, 2],
    [3, 4]
  ]
}

To support this pattern, add pair, triple, quad codecs (and/or tuple2, tuple3, tuple4 etc.)

When decoding arrays as tuples, unexpected extra elements should be ignored.

Objects as dictionaries

JSON objects can be used like dictionaries, so add a combinator for parsing this style, e.g.

{
  "GBP": 0.77,
  "EUR": 0.84
}
let rates: codec (list (string, float)) = JsonCodec.(dict number);

Look into using Hashtbl instead of list (string, 'a).

Document Error Reporting

First, thanks for all of your hard work on this.

Useful error messages are perhaps the most important feature of any serialization/deserialization framework. What sorts of errors does this library provide?

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.