Reading and writing JSON / YAML / TOML using pkgs.formats

Hello community,

I looked at Starship Nix code and I saw that it is using pkgs.formats package to convert Nix attr. set into TOML. Of course the opposite direction from TOML to Nix is builtins.fromTOML. JSON has the same tooling, you can use pkgs.formats to convert to JSON or you can use builtins to convert from JSON.

But what about YAML? I can convert to YAML using pkgs.formats but how to read YAML?

And is there a way how to do all conversions without creating files (without derivations)? I mean: YAML/JSON/TOML (as string) <==> Nix attr. set?

Thank you so much for this excellent community!

1 Like

Nothing builtin yet. See

and

1 Like