Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

cxa/JsonR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published