Low-level JSON parsing and pretty-printing library for OCaml
368
stars
443
commits
OCaml
primary language
Aug 1, 2025
updated
The Yojson libraries parse JSON and JSON5 data into a nested OCaml tree data structures.
The documentation of both Yojson and Yojson-five can be found on OCaml.org.
A simple example on how to parse JSON from a string literal.
let json_string = {|
{"number" : 42,
"string" : "yes",
"list": ["for", "sure", 42]}|}
(* val json_string : string *)
let json = Yojson.Safe.from_string json_string
(* val json : Yojson.Safe.t *)
let () = Format.printf "Parsed to %a" Yojson.Safe.pp json
The examples directory contains more examples.
Yojson is a pretty common choice for parsing JSON in OCaml, as such it is the
base for a number of tools and libraries that are built on top of it.
ppx_deriving_yojson to
automatically generate code that converts between Yojson.Safe.t and custom
OCaml typesppx_yojson_conv, an
alternative to ppx_deriving_yojson from Jane Street with different design
decisionsatd, generates mapping code from .atd
specification files and can be used in multiple languagesjsonm is an alternate JSON parser
that parses JSON into a stream of items, so the complete data structure does
not have to be in memory.Yojson is developed and maintained by volunteers — users like you. Various issues are in need of attention. If you'd like to contribute, please leave a comment on the issue you're interested in, or create a new issue. Experienced contributors will guide you as needed.
There are many simple ways of making a positive impact. For example, you can...
Yojson.Check out in particular good first time issues and other issues with which we could use some help.
Yojson is licensed under the 3-clause BSD license, see LICENSE.md for
details.
(top 30 of 36)
OCaml
98.6%
Dune
1.0%
Low-level JSON parsing and pretty-printing library for OCaml
368
stars
443
commits
OCaml
primary language
Aug 1, 2025
updated
The Yojson libraries parse JSON and JSON5 data into a nested OCaml tree data structures.
The documentation of both Yojson and Yojson-five can be found on OCaml.org.
A simple example on how to parse JSON from a string literal.
let json_string = {|
{"number" : 42,
"string" : "yes",
"list": ["for", "sure", 42]}|}
(* val json_string : string *)
let json = Yojson.Safe.from_string json_string
(* val json : Yojson.Safe.t *)
let () = Format.printf "Parsed to %a" Yojson.Safe.pp json
The examples directory contains more examples.
Yojson is a pretty common choice for parsing JSON in OCaml, as such it is the
base for a number of tools and libraries that are built on top of it.
ppx_deriving_yojson to
automatically generate code that converts between Yojson.Safe.t and custom
OCaml typesppx_yojson_conv, an
alternative to ppx_deriving_yojson from Jane Street with different design
decisionsatd, generates mapping code from .atd
specification files and can be used in multiple languagesjsonm is an alternate JSON parser
that parses JSON into a stream of items, so the complete data structure does
not have to be in memory.Yojson is developed and maintained by volunteers — users like you. Various issues are in need of attention. If you'd like to contribute, please leave a comment on the issue you're interested in, or create a new issue. Experienced contributors will guide you as needed.
There are many simple ways of making a positive impact. For example, you can...
Yojson.Check out in particular good first time issues and other issues with which we could use some help.
Yojson is licensed under the 3-clause BSD license, see LICENSE.md for
details.
(top 30 of 36)
OCaml
98.6%
Dune
1.0%