All Projects → mlms13 → bs-decode

mlms13 / bs-decode

Licence: MIT license
Type-safe JSON decoding for ReasonML and OCaml

Programming Languages

reason
219 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to bs-decode

re-typescript
An opinionated attempt at finally solving typescript interop for ReasonML / OCaml.
Stars: ✭ 68 (-35.24%)
Mutual labels:  decoding, reasonml
bs-reason-apollo
ReactApollo bindings for BS
Stars: ✭ 23 (-78.1%)
Mutual labels:  reasonml
morton-nd
A header-only compile-time Morton encoding / decoding library for N dimensions.
Stars: ✭ 78 (-25.71%)
Mutual labels:  decoding
vorbis aotuv
"aoTuV" is library for encoding and decoding of OggVorbis
Stars: ✭ 35 (-66.67%)
Mutual labels:  decoding
solar-weather
React Native Weather App w. Realm, Redux, ReasonReact & Forecast.io
Stars: ✭ 13 (-87.62%)
Mutual labels:  reasonml
nibbledb
a byte-sized time series database
Stars: ✭ 23 (-78.1%)
Mutual labels:  reasonml
bs-remotedata
RemoteData and WebData to use with bs-fetch for BuckleScript
Stars: ✭ 18 (-82.86%)
Mutual labels:  reasonml
reason-hooks-testing-library
ReasonML bindings for react-hooks-testing-library
Stars: ✭ 24 (-77.14%)
Mutual labels:  reasonml
tea-chess
A chess-themed tutorial on writing an SPA in Bucklescript-TEA
Stars: ✭ 28 (-73.33%)
Mutual labels:  reasonml
reason-cookie
A simple way to use cookies in Reason (OCaml) on the frontend. 🍪
Stars: ✭ 18 (-82.86%)
Mutual labels:  reasonml
CTF-CryptoTool
CTF-CryptoTool is a tool written in python, for breaking crypto text of CTF challenges. It tries to decode the cipher by bruteforcing it with all known cipher decoding methods easily. Also works for the cipher which does not have a key.
Stars: ✭ 38 (-63.81%)
Mutual labels:  decoding
revery-packager
Helper utility to package Revery applications into installable app bundles
Stars: ✭ 38 (-63.81%)
Mutual labels:  reasonml
bs-react-fela
BuckleScript bindings for react-fela
Stars: ✭ 21 (-80%)
Mutual labels:  reasonml
reason-tree-sitter
ReasonML bindings for tree-sitter
Stars: ✭ 22 (-79.05%)
Mutual labels:  reasonml
bs-axios
Bucklescript bindings for axios
Stars: ✭ 74 (-29.52%)
Mutual labels:  reasonml
streaming
Fast, safe and composable streaming abstractions.
Stars: ✭ 104 (-0.95%)
Mutual labels:  reasonml
re-use
⚛️ 🎣 A collection of hooks for ReasonReact
Stars: ✭ 27 (-74.29%)
Mutual labels:  reasonml
vscode-graphiql-explorer
Use GraphiQL + GraphiQL Explorer to build your GraphQL operations, right from inside of VSCode.
Stars: ✭ 35 (-66.67%)
Mutual labels:  reasonml
jsoo-react
js_of_ocaml bindings for ReactJS. Based on ReasonReact.
Stars: ✭ 126 (+20%)
Mutual labels:  reasonml
Symbolic-Regression
predicting equations from raw data with deep learning
Stars: ✭ 48 (-54.29%)
Mutual labels:  decoding

bs-decode

build status test coverage npm version license

Read the Documentation

Decode JSON values into structured ReasonML and OCaml types. Inspired by Elm's Json.Decode and the Decode Pipeline, bs-decode is an alternative to bs-json that focuses on structured, type-safe error handling, rather than exceptions. Additionally, bs-decode collects up everything that went wrong while parsing the JSON, rather than failing on the first error.

Installation

Install via npm:

npm install --save bs-decode relude bs-bastet

Update your bsconfig.json

"bs-dependencies": [
  "bs-bastet",
  "bs-decode",
  "relude"
],

Usage

The following is available to give you an idea of how the library works, but the complete documentation will probably be more useful if you want to write your own decoders.

// imagine you have a `user` type and `make` function to construct one
type user = {
  name: string,
  age: int,
  isAdmin: bool,
  lastLogin: option(Js.Date.t)
};

let make = (name, age, isAdmin, lastLogin) =>
  { name, age, isAdmin, lastLogin };

/**
 * Given a JSON value that looks like:
 * { "name": "Michael", "age": 32, "roles": ["admin"] }
 *
 * you can write a function to convert this JSON into a value of type `user`
 */
module Decode = Decode.AsResult.OfParseError; // module alias for brevity

let decode = json =>
  Decode.Pipeline.(
    succeed(make)
    |> field("name", string)
    |> field("age", intFromNumber)
    |> field("roles", map(List.contains("admin"), list(string)))
    |> optionalField("lastLogin", date)
    |> run(json)
  );

let myUser = decode(json); /* Ok({ name: "Michael", ...}) */

Contributing

All contributions are welcome! This obviously includes code changes and documentation improvements (see CONTRIBUTING), but we also appreciate any feedback you want to provide (in the form of Github issues) about concepts that are confusing or poorly explained in the docs.

License

Released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].