No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
nnra6864 9bdef5a5a4 fix: The package includes the code adding entries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 22:28:54 +01:00
.gitignore chore: Zig's caches and fetched packages are ignored 2026-11-10 16:09:48 +01:00
build.zig feat: kosm_json sets values by path in JSON and JSONC files 2026-11-06 15:53:44 +01:00
build.zig.zon fix: The package includes the code adding entries 2026-11-13 22:28:54 +01:00
inserting.zig feat: An app can add its own key or list entry to JSON, keeping comments and layout 2026-11-13 22:27:21 +01:00
JsoncParser.zig refactor: Code, error messages and READMEs no longer cite design numbers 2026-11-09 20:17:19 +01:00
README.md feat: An app can add its own key or list entry to JSON, keeping comments and layout 2026-11-13 22:27:21 +01:00
root.zig feat: An app can add its own key or list entry to JSON, keeping comments and layout 2026-11-13 22:27:21 +01:00

kosm_json

JSON for kosm: two adapters enabling edit, and generate for json.

  • json claims .json files: strict JSON, where a trailing comma is a syntax error (the file is refused with its line, as with any syntax error). It also writes whole files through generate, indented by two spaces.
  • jsonc claims .jsonc files and also takes // and /* */ comments and trailing commas. Pass .lang = "jsonc" for a .json file written that way, such as VS Code's settings.json.

Both can add an app's own include entry with insert (a key at the end of an object) and append (an element at the end of an array): the entry goes on its own line after the last one, indented like it, with comments left where they are and a trailing comma kept.

var settings = try output.edit(.{ .files = "~/.config/Code/User/settings.json", .lang = "jsonc" });
try settings.set("\"editor.fontSize\"", 16);                              // a key holding a dot is quoted
try settings.set(.{ "workbench.colorCustomizations", "editor.background" }, color);

Only the value's bytes change; comments, spacing and key order stay as they are.

Value Written as
string a JSON string, escaped
color a JSON string in the file's color format; default #rrggbb
integer, float the number; floats at the file's precision, never infinity or NaN
bool true or false; format.boolean must stay .true_false
struct, list an object or array on one line
kosm.raw(text) text, verbatim

Paths name object keys only. Reach array elements with nodes, elements and replace; nodes("") is the top-level value, for a file that is one array.