devbox icon indicating copy to clipboard operation
devbox copied to clipboard

Support `.json5` extension

Open djgoku opened this issue 1 year ago • 0 comments

What problem are you trying to solve?

I want to validate my devbox.json and plugin.json with check-jsonschema which can validate both .json and .json5 files.

Validate devbox.json

dj_goku % devbox init
dj_goku % devbox add python311Packages.json5 check-jsonschema
Info: Adding package "python311Packages.json5@latest" to devbox.json
Info: Adding package "check-jsonschema@latest" to devbox.json
dj_goku % devbox shell
✓ Computed the Devbox environment.
Starting a devbox shell...
(devbox) dj_goku % check-jsonschema --schemafile https://raw.githubusercontent.com/jetpack-io/devbox/main/.schema/devbox.schema.json devbox.json 
ok -- validation done
(devbox) dj_goku % cat devbox.json 
{
  "$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
  "packages": [
    "python311Packages.json5@latest",
    "check-jsonschema@latest"
  ],
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}

validate devbox.json5

(devbox) dj_goku % check-jsonschema --schemafile https://raw.githubusercontent.com/jetpack-io/devbox/main/.schema/devbox.schema.json devbox.json5
ok -- validation done
(devbox) dj_goku % cat devbox.json5
{
  // a comment
  "$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
  "packages": [
    "python311Packages.json5@latest",
    "check-jsonschema@latest"
  ],
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}
(devbox) dj_goku % diff -u devbox.json devbox.json5
--- devbox.json	2024-03-21 18:43:04.503029111 -0500
+++ devbox.json5	2024-03-21 18:44:21.621139194 -0500
@@ -1,4 +1,5 @@
 {
+  // a comment
   "$schema": "https://raw.githubusercontent.com/jetpack-io/devbox/0.10.1/.schema/devbox.schema.json",
   "packages": [
     "python311Packages.json5@latest",

What solution would you like?

The ability to use .json (without comments) or .json5 (with comments).

Alternatives you've considered

I can copy devbox.json5 to devbox.json and use this newly copied devbox.json with devbox shell.

djgoku avatar Mar 21 '24 23:03 djgoku