Skip to content

cxa/bs-json-keypather

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Keypath Navigator for BuckleScript

Navigate JSON with keypath.

Basic usage

Add @cxa/bs-json-keypather to your dependencies, and configure your bsconfig.json like:

{
  "bs-dependencies": ["@cxa/bs-json-keypather"]
}

For this JSON:

{
  "title": { "main": "Bs_json_keypather", "sub": "is awesome" },
  "version": { "major": 1, "minor": 2 },
  "version_float": 1.2,
  "production_ready": true,
  "reason": null,
  "arr": [4, 5, 6]
}

You can navigate main title with Bs_json_keypather.string_for "title.main" json. More:

val json_for : Js.String.t -> Js.Json.t -> (Js.Json.t, error) Belt.Result.t
val value_for :
  Js.String.t ->
  Js.Json.t -> (Js.Json.t -> 'a option) -> ('a, error) Belt.Result.t
val bool_for : Js.String.t -> Js.Json.t -> (bool, error) Belt.Result.t
val string_for : Js.String.t -> Js.Json.t -> (Js.String.t, error) Belt.Result.t
val float_for : Js.String.t -> Js.Json.t -> (float, error) Belt.Result.t
val int_for : Js.String.t -> Js.Json.t -> (int, error) Belt.Result.t
val object_for :
  Js.String.t -> Js.Json.t -> (Js.Json.t Js.Dict.t, error) Belt.Result.t
val array_for :
  Js.String.t -> Js.Json.t -> (Js.Json.t array, error) Belt.Result.t
val is_null_for : Js.String.t -> Js.Json.t -> bool

Advance usage

Use your favorite Result type e.g. CCResult with functor Bs_json_keypather_impl.Make.

module My_json_keypather =
  Bs_json_keypather_impl.Make(CCResult)

Development

  • npm run/yarn watch
  • npm run/yarn test

About

Navigate JSON with keypath for BuckleScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published