Skip to content

🧮 A web app to quickly convert JSONC to Nix values.

License

Notifications You must be signed in to change notification settings

fmway/jsonc-to-nix

 
 

Repository files navigation

JSONC to Nix

A web app to quickly convert JSONC to Nix values. And yes I now know there is a built-in for that. But it only support JSON, not JSONC😊...

Development

git clone https://github.com/fmway/jsonc-to-nix.git
cd jsonc-to-nix
pnpm install
pnpm dev

Alternative

If you want to use nix expression instead of web app, you can use this code:

let
  fromJSONC = jsonc:
    builtins.fromJSON (
      builtins.readFile (
        pkgs.runCommand "from-jsonc"
          {
            FILE = pkgs.writeText "file.jsonc" jsonc;
            allowSubstitutes = false;
            preferLocalBuild = true;
          }
          ''
            # it's awkward, but it's works 😏
            ${pkgs.gcc}/bin/cpp -P -E "$FILE" > $out
            # or clang
          ''
      )
    );
in
fromJSONC ''
{
  "just": {
    "work": /* it must'be work, don't use comma in last value */ true
  }
}
''
# or
# fromJSONC (builtins.readFile ./your-file.jsonc)

(reference: https://stackoverflow.com/a/77493974)

Thanks To

Related Project

License

MIT

About

🧮 A web app to quickly convert JSONC to Nix values.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vue 49.9%
  • TypeScript 33.5%
  • HTML 12.8%
  • Shell 3.8%