Code: YAML, TOML, JSON and XML
YAML, TOML, JSON and XML: the code
The programs behind the slides. They use only system libraries (json, toml, yaml, xml), need no server and no decks, and run with Jennifer 0.27.0. Run each one from this folder, because the readers open the app.* files by relative path.
app.json,app.toml,app.yaml,app.xml: the one small config in four formats ("The config: JSON and TOML", "The config: YAML and XML").read.j: reads each file into the sameConfigstruct with the typed accessors and prints all four ("Reading into one struct"). Run:jennifer run read.jtraps.j:typeOfper key for YAML, JSON and TOML input, number promotion, the YAML 1.2 traps, TOML dates and[[item]], and what TOML cannot encode ("What each format can hold", "JSON numbers", "YAML: version 1.2 and its traps", "TOML: dates, tables, no null"). Run:jennifer run traps.jmisc.j: a list of tables by index, a missing XML attribute, duplicate attributes and keys, a YAML hex int ("XML: everything is a string", "TOML: dates, tables, no null"). Run:jennifer run misc.jwrite.j: a struct encoded withjson,yamlandtoml, and an XML tree built by hand ("Writing: a struct encodes directly"). Run:jennifer run write.jconvert.j: handles do not convert between libraries, and which round trips compare equal ("Round trips", "Converting between formats"). Run:jennifer run convert.jcomments.j: decoding drops comments, and0xffencodes back as255("Round trips", "TOML: dates, tables, no null"). Run:jennifer run comments.jerrors.j: the error kind and message for each malformed input in the table ("Malformed input throws"). Run:jennifer run errors.jlimits.j: strictconvert.toInt, a YAML alias bomb, an oversized YAML input, an XML entity bomb and deep nesting, all caught by kind ("XML: everything is a string", "Hostile input: kind "limit""). Run:jennifer run limits.jsafe.j:json.decodeWithwith lowered caps, telling kind"limit"from a malformed document ("Telling "too big" from "malformed""). Run:jennifer run safe.j
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 2.1 KiB | raw |
| app.json | 159 B | raw |
| app.toml | 126 B | raw |
| app.xml | 160 B | raw |
| app.yaml | 113 B | raw |
| comments.j | 109 B | raw |
| convert.j | 758 B | raw |
| errors.j | 1012 B | raw |
| limits.j | 1.1 KiB | raw |
| misc.j | 583 B | raw |
| read.j | 1.3 KiB | raw |
| safe.j | 601 B | raw |
| traps.j | 1.3 KiB | raw |
| write.j | 735 B | raw |