2.3.1 • Published 6 years ago

json-r v2.3.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

JsonR

Deprecated. Use https://github.com/cxa/bs-json-keypather instead.

A BuckleScript lib for handling JSON in Result favor, written in ReasonML.

Usage

Add json-r to your project's dependencies by yarn or npm, And add it to bs-dependencies for bsconfig.json, e.g.

{
  "name": "coolproj",
  "bs-dependencies": ["json-r"]
}

Basic example

open JsonR.Json;
open Js_result;

let json = parse_string json_source;

/* Access a field and its value, return a Js_result type */

let title = json |> string_for "title";

/* or more verbose */
let title = json |> member "title" |> to_string;


/* you can also pass key path */
let age = json |> int_for "author.age";

/ * or */
let age = json |> member "author.age" |> to_int;

switch age {
| Ok a => DoWhatYouWant a
| Error e => HeyWeCantParseOutTheAge_CheckTheErrorMessage e
};

You can open __tests__/test.re to view more examples.

Advance usage

Need to use the another Result type such as Containers.Result? Just Module Json = JsonR.Impl Containers.Result;.

LICENSE

MIT.

2.3.1

6 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago