https://github.com/sempruijs/json2nix
A json to nix converterwritten in Haskell
https://github.com/sempruijs/json2nix
converter flake haskell json nix
Last synced: 11 months ago
JSON representation
A json to nix converterwritten in Haskell
- Host: GitHub
- URL: https://github.com/sempruijs/json2nix
- Owner: sempruijs
- License: mit
- Created: 2024-07-02T21:27:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-04T21:56:30.000Z (about 1 year ago)
- Last Synced: 2025-04-04T13:14:03.045Z (11 months ago)
- Topics: converter, flake, haskell, json, nix
- Language: Haskell
- Homepage:
- Size: 58.6 KB
- Stars: 14
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json2nix
A json 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,
"1": [],
"2": []
}
```
And you want something like this:
```nix
{
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;
"1" = [];
"2" = [];
}
```
You can do so by enabling nix flakes and run the following command in your shell:
```shell
nix run github:sempruijs/json2nix
```
This will install the required tools.
json2nix will ask two questions:
1. Choose a file path.
This could be something like: ```config.json```.
2. Choose a file name for the new nix file.
You can type something or hit enter for the suggestion.
This would be something like: ```config.nix```
## Contributing
If you find a bug please submit [an issue](https://github.com/sempruijs/json2nix/issues) or [pull request](https://github.com/sempruijs/json2nix/pulls).
MIT license