state-machine-systems / jsoncodec Goto Github PK
View Code? Open in Web Editor NEWJSON combinator library for BuckleScript/Reason
License: Apache License 2.0
JSON combinator library for BuckleScript/Reason
License: Apache License 2.0
Add fixpoint and/or lazy combinators to allow recursive structures.
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
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).
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.
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)
.
The package name listed in bsconfig.json
is bs-json-codec
, while in package.json
it is listed as json-codec
. This causes issues with both webpack and require.js. Would it be possible to change either of them to match the other?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.