Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Really Knowing JSON: RFC 8259, Number Precision, Duplicate Keys, JSONC, JSON5 and JSON Lines
Because RFC 8259 leaves duplicate keys and number precision undefined, Node.js, Python, jq and .NET can read the same JSON differently: all four take the last value of a repeated key and only JavaScript rounds an ID above 2^53. We show BOMs, NaN, leading zeros, JSONC in appsettings.json, JSON5 and a JSON Lines version of Bookstore's order export with real output.
YAML 1: Syntax, Types and the "Norway Problem": Reading a YAML File Correctly
The type of an unquoted YAML value depends on the rule set the parser applies: in YAML 1.1 NO is false, 12:30 a number and 0755 octal; in YAML 1.2 all three differ. We run PyYAML, ruamel.yaml, js-yaml, YamlDotNet, yq, Docker Compose and kubectl on the same file and show three real type errors in Bookstore's compose.yaml and Kubernetes manifest.
YAML 2: Multiline Strings, Anchors/Aliases, Merge Keys, Multiple Documents and KYAML
Write scripts with |, long prose with >, and use |- for single-line values such as secrets, otherwise a \n is appended. The merge key (<<) is not in YAML 1.2: Compose, kubectl and kubeconform support it, GitHub Actions does not, and js-yaml 5 needs an option. We show multiple documents, the document boundary of anchors, unsafe tags, KYAML and a yamllint rule set for Bookstore with real output.
TOML, INI, .env and the Rest: Which Configuration Format When?
Choose by who reads the file: if .NET is the only reader, JSON and environment variables are enough; if several tools read the same .env, write it in the strictest common subset. We read one .env with Compose, Node.js, dotenv, python-dotenv and bash, one INI with .NET, Python and git, and show the differences, TOML 1.1's date types and Bookstore.Api's setting in five formats becoming one configuration.
Validating Configuration with JSON Schema: Editor IntelliSense, SchemaStore and Validation in CI
The .NET binder silently ignores a misspelled settings key; additionalProperties: false in JSON Schema catches it while you write the file and in CI. We write a 2020-12 schema for Bookstore.Api and validate with SchemaStore, a VS Code mapping, a YAML schema comment, check-jsonschema, ajv and JsonSchema.Net, showing with real output how mixed drafts and format checking differ.
jq and yq in Depth: Querying, Transforming and Editing JSON and YAML on the Command Line
jq returns a missing field as null instead of an error and exits with 0 on empty results too; add -e to every filter you use as a condition in CI. With output from Bookstore.Api, kubectl, dotnet list package and the GitHub API we show select, group_by, reduce inputs, --arg/--argjson and @csv, updating an image tag with yq while keeping comments, the two different yq tools and Windows quoting.