This package has been deprecated

Author message:

use @cxa/@cxa/bs-json-keypather instead

json-r

2.3.1 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i json-r

Weekly Downloads

17

Version

2.3.1

License

MIT

Unpacked Size

11 kB

Total Files

7

Last publish

Collaborators

  • cxa