package mjson
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=894754a6d9e144bdae088db09d4d8b6d5e534c3b567fdf1f2ddf56f0c398d236
sha512=9fd065c037049d21161d19b7fe7350e1495e834263a55e0a0c727ae47733d22a88f55fb8377c9a5385ba82a326b0b55d4ea48bc2bf3d707ff3c36983f8224099
Description
Composable, applicative and monadic DSL for decoding Yojson values
Added to opam-repository:
README
mjson is a small OCaml library for decoding JSON values from more low-level JSON libraries such as Yojson.
The current implementation comes with a thin layer on top of Yojson (Safe and Basic).
Examples
type person =
{ name : string
; age : int
}
let make_person name age = { name; age }
(* (monadic) decoder for Yojson.Safe.t values into a person. *)
let person_decoder =
let open Mjson.Decoder.Yojson.Safe in
let open Mjson.Decoder.Yojson.Safe.Syntax in
(* decode the field "name" into a string *)
let* name = field "name" string in
(* decode the field "age" into an int *)
let* age = field "age" int in
(* if all went well [return] the person (or any error that might have
occured along the way. *)
return @@ make_person name age
;;Example utop session
utop # person_decoder @@ `Assoc [ "name", `String "Ursula"; "age", `Int 88];;
- : (person, Mjson.Decoder.Yojson.Safe.Error.t) result =
Ok {name = "Ursula"; age = 88}
utop # person_decoder @@ `Assoc [ "name", `String "Ursula"; "age", `Bool true];;
- : (person, Mjson.Decoder.Yojson.Safe.Error.t) result =
Error
(Mjson.Decoder.Yojson.Safe.Error.Field ("age",
Mjson.Decoder.Yojson.Safe.Error.Failure ("not an int", `Bool true)))
See the tests for more examples.
Building the Code
This packages comes with a nix DevShell. All commands are intended for use within the provided (default) devShell.
$ make repl # opens a utop repl with the project loaded
$ make test # runs all tests
$ make doc # generate all documentation
Dependencies (5)
- ppx_deriving
- alcotest
-
yojson
>= "2.0.0" -
dune
>= "3.11" & >= "3.11" -
ocaml
>= "4.14.0"
Dev Dependencies (1)
-
odoc
with-doc
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building mjson with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.2.1 (this version) | n/a | good | good | good | good |
| 0.1.1 | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure