Skip to content

A json/yaml/toml to nix converter written in Haskell

License

Notifications You must be signed in to change notification settings

cloudandheat/json2nix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A json/yaml/toml to nix converter written in Haskell

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Haskell 69.1%
  • Nix 30.8%
  • Shell 0.1%