NAML is a subset of YAML that only requires a JSON parser (and a tiny conversion func).
If you ever thought, I want something like a simple YAML parser but man those YAML parsers are monstrous, this solution is for you.
The format is basically HTTP headers where all values are JSON:
template: "home"
page_classes: ["page--jumbo"]
cta: {
"primary": {
"title": "Click me",
"href": "http://example.com/"
}
}
Syntax:
- Each non-empty line is a
key: value
pair. - Each value is a valid JSON.
- You can continue a value on multiple lines by indenting all continuation lines (using spaces or tabs).
#
starts a comment if it's the first non-whitespace character on the line.
That's it.
This is valid YAML, and can be trivially converted to an actual JSON, so that you can use all features of your favorite JSON parser.
Copy naml.go
into your project. Not worth adding a dependency over it. This is a good example of a piece of code that's done and not expected to ever change.
But, of course, if your project is already a dumpster fire, nobody is stopping you from doing go get github.com/andreyvit/naml@latest
.
Then you just do json.Unmarshal(naml.Convert(data), ...)
.
For bonus points, combine it with andreyvit/jsonfix to allow trailing commas in that inline JSON.
Umm. Well if you need this to run on older versions of Go and backport to not use bytes.Lines
, please share.
Bug fixes are welcome too, of course.
Copyright (c) 2025, Andrey Tarantsov.
I release this code under a MIT license and a Zero-Clause BSD license.
Zero-Clause BSD license allows usage of this code without attribution and without preserving the copyright notice — basically just copy it into your project.