Yaml encoder/decoder for OCaml jsont codecs
1# yamlt - YAML codec using Jsont type descriptions
2
3Yamlt provides YAML streaming encode/decode that interprets Jsont.t type descriptions, allowing the same codec definitions to work for both JSON and YAML.
4
5## Key Features
6
7- Use the same Jsont.t codec for both JSON and YAML formats
8- Streaming encode/decode with configurable depth and node limits
9- Support for YAML-specific features (scalars, sequences, mappings)
10- Billion laughs protection with configurable limits
11- Multiple output formats (block, flow, layout preservation)
12
13## Usage
14
15```ocaml
16(* Define a codec once using Jsont *)
17module Config = struct
18 type t = { name: string; port: int }
19 let make name port = { name; port }
20 let jsont =
21 Jsont.Object.map ~kind:"Config" make
22 |> Jsont.Object.mem "name" Jsont.string ~enc:(fun c -> c.name)
23 |> Jsont.Object.mem "port" Jsont.int ~enc:(fun c -> c.port)
24 |> Jsont.Object.finish
25end
26
27(* Use the same codec for both JSON and YAML *)
28let from_json = Jsont_bytesrw.decode_string Config.jsont json_str
29let from_yaml = Yamlt.decode_string Config.jsont yaml_str
30```
31
32For encoding:
33
34```ocaml
35(* Encode to YAML with different formats *)
36let config = Config.make "server" 8080
37
38(* Block style (default) *)
39let yaml_block = Yamlt.encode_string Config.jsont config
40
41(* Flow style (JSON-like) *)
42let yaml_flow = Yamlt.encode_string ~format:Flow Config.jsont config
43```
44
45## Installation
46
47```
48opam install yamlt
49```
50
51## Documentation
52
53API documentation is available at https://tangled.org/@anil.recoil.org/ocaml-yamlt or via:
54
55```
56opam install yamlt
57odig doc yamlt
58```
59
60## License
61
62ISC