Yaml 0.1.0 released

This is an OCaml library to parse and generate the YAML file format. It is intended to interoperable with the Ezjsonm JSON handling library, if the simple common subset of Yaml is used. Anchors and other advanced Yaml features are not implemented in the JSON compatibility layer.

The Yaml module docs are browseable online.

Source: https://github.com/avsm/ocaml-yaml

Example of use

Install the library via opam install yaml, and then execute a toplevel via utop. You can also build and execute the toplevel locally:

$ opam install yaml
$ utop
# #require "yaml";;
# Yaml.of_string "foo";;
- : Yaml.value Yaml.res = Result.Ok (`String "foo")
# Yaml.of_string "- foo";;
- : Yaml.value Yaml.res = Result.Ok (`A [`String "foo"])
# Yaml.to_string (`O ["foo1", `String "bar1"; "foo2", `Float 1.0]);;
- : string Yaml.res = Result.Ok "foo1: bar1\nfoo2: 1.\n"

The README contains more information about how the library is structured. This repository is a reasonable example of how to use ocaml-ctypes and stub generation to bind to a C library without writing any actual C code for the bindings.

10 Likes

Nice! When I picked OCaml back up (just a month ago), a YAML binding was the very first library that I looked for. I found two libraries on github, but nothing in OPAM.

YAML, JSON, and SQLite are the three – er, YAML, JSON, SQLite, and curl or similar are the four – er, YAML, JSON, SQlite, MySQL, and curl are the five minimum libraries if OCaml is to be an easily drop-in replacement for your typical sysadmin-type scripts.

2 Likes

Glad to hear it! Let me know if you end up using it for anything.