Skip to content

Latest commit

 

History

History
80 lines (61 loc) · 1.51 KB

README.md

File metadata and controls

80 lines (61 loc) · 1.51 KB

json2nix

A json/yaml/toml to nix converter written in Haskell. You can use this easily with a flake. Unformatted json is also supported.

Usage

If you have something like this:

{
    "name": "Alice",
    "age": 21,
    "length_in_meters": 1.8,
    "best_friends": [
        {
            "name": "bob",
            "age": 19,
        },
        {
            "name": "Sem",
            "age": 19,
        }
    ],
    "favorite_movie": null,
    "(some)%wild;key": 5
}

And you want something like this:

{
  name = "Alice";
  age = 21;
  length_in_meters = 1.8;
  best_friends = [
    {
      name = "bob";
      age = 19;
    }
    {
      name = "Sem";
      age = 19;
    }
  ];
  favorite_movie = null;
  "(some)%wild;key" = 5;
}

You can do so by enabling nix flakes and run the following command in your shell:

nix run github:cloudandheat/json2nix [inputfile] [output]

Both arguments may be omitted or set to "-" in which case json2nix will read from stdin resp. write to stdout.

YAML and TOML

By virtue of yq, this flake also contains two packages yaml2nix and toml2nix that can be used just like json2nix:

nix run github:cloudandheat/json2nix#yaml2nix [inputfile] [output]
nix run github:cloudandheat/json2nix#toml2nix [inputfile] [output]

Contributing

If you find a bug please submit an issue or pull request.

MIT license