https://github.com/cxa/bs-json-keypather
Navigate JSON with keypath for BuckleScript
https://github.com/cxa/bs-json-keypather
Last synced: 9 months ago
JSON representation
Navigate JSON with keypath for BuckleScript
- Host: GitHub
- URL: https://github.com/cxa/bs-json-keypather
- Owner: cxa
- License: mit
- Created: 2018-03-20T08:06:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-26T17:20:12.000Z (almost 8 years ago)
- Last Synced: 2025-01-22T09:44:41.910Z (over 1 year ago)
- Language: OCaml
- Homepage:
- Size: 49.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```json
{
"bs-dependencies": ["@cxa/bs-json-keypather"]
}
```
For this JSON:
```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:
```ocaml
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`.
```ocaml
module My_json_keypather =
Bs_json_keypather_impl.Make(CCResult)
```
## Development
* `npm run/yarn watch`
* `npm run/yarn test`