uncenter / json-to-nix

🧮 A web app to quickly convert JSON to Nix values.
https://json-to-nix.pages.dev/
MIT License
9 stars 1 forks source link

Attribute names are not in quotation marks #1

Closed I-Want-ToBelieve closed 2 months ago

I-Want-ToBelieve commented 2 months ago

I tried converting vscode's settings.json to nix and everything was fine, but I found that the property names were not in quotation marks

json:

{
  "[dart]": {
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "editor.rulers": [90],
    "editor.selectionHighlight": false,
    "editor.suggest.snippetsPreventQuickSuggestions": false,
    "editor.suggestSelection": "first",
    "editor.tabCompletion": "onlySnippets",
    "editor.wordBasedSuggestions": "off"
  },

  "workbench.iconTheme": "catppuccin-mocha",
  "workbench.list.automaticKeyboardNavigation": false
}

nix:

{
  [dart] = {
    editor.formatOnSave = true;
    editor.formatOnType = true;
    editor.rulers = [
      90
    ];
    editor.selectionHighlight = false;
    editor.suggest.snippetsPreventQuickSuggestions = false;
    editor.suggestSelection = "first";
    editor.tabCompletion = "onlySnippets";
    editor.wordBasedSuggestions = "off";
  };
  workbench.iconTheme = "catppuccin-mocha";
  workbench.list.automaticKeyboardNavigation = false;
}

Expected is:

nix:

{
  "[dart]" = {
    "editor.formatOnSave" = true;
    "editor.formatOnType" = true;
    "editor.rulers" = [
      90
    ];
    "editor.selectionHighlight" = false;
    "editor.suggest.snippetsPreventQuickSuggestions" = false;
    "editor.suggestSelection" = "first";
    "editor.tabCompletion" = "onlySnippets";
    "editor.wordBasedSuggestions" = "off";
  };
  "workbench.iconTheme" = "catppuccin-mocha";
  "workbench.list.automaticKeyboardNavigation" = false;
}
uncenter commented 2 months ago

Keys don't need to be wrapped in quotation marks unless they have certain characters right? It is a bug that [dart] isn't in quotes but the rest is expected.

uncenter commented 2 months ago

I've fixed it in https://github.com/uncenter/json-to-nix/commit/232b5d5da6c2dec0f76b63a47c108d428e4e438d. Your original JSON now becomes:

{
  "[dart]" = {
    editor.formatOnSave = true;
    editor.formatOnType = true;
    editor.rulers = [
      90
    ];
    editor.selectionHighlight = false;
    editor.suggest.snippetsPreventQuickSuggestions = false;
    editor.suggestSelection = "first";
    editor.tabCompletion = "onlySnippets";
    editor.wordBasedSuggestions = "off";
  };
  workbench.iconTheme = "catppuccin-mocha";
  workbench.list.automaticKeyboardNavigation = false;
}

Only keys that have to be quoted are quoted.

I-Want-ToBelieve commented 2 months ago

@uncenter hi

Similar to workbench.iconTheme, quotation marks are also required because workbench.iconTheme is the name of the key.

uncenter commented 2 months ago

Totally right! Let me make another fix, sorry!

uncenter commented 2 months ago

Fixed in https://github.com/uncenter/json-to-nix/commit/6a26a4439f0d95de0fb6a83a1c6b29edb2c24386!