json.md

 1# JSON
 2
 3JSON support is available natively in Zed.
 4
 5- Tree-sitter: [tree-sitter/tree-sitter-json](https://github.com/tree-sitter/tree-sitter-json)
 6- Language Server: [zed-industries/json-language-server](https://github.com/zed-industries/json-language-server)
 7
 8## JSONC
 9
10Zed also supports a super-set of JSON called JSONC, which allows single line comments (`//`) in JSON files.
11While editing these files you can use `cmd-/` (macOS) or `ctrl-/` (Linux) to toggle comments on the current line or selection.
12
13## JSONC Prettier Formatting
14
15If you use files with the `*.jsonc` extension when using `Format Document` or have `format_on_save` enabled, Zed invokes Prettier as the formatter. Prettier has an [outstanding issue](https://github.com/prettier/prettier/issues/15956) where it will add trailing commas to files with a `jsonc` extension. JSONC files which have a `.json` extension are unaffected.
16
17To workaround this behavior you can add the following to your `.prettierrc` configuration file:
18
19```json
20{
21  "overrides": [
22    {
23      "files": ["*.jsonc"],
24      "options": {
25        "parser": "json",
26        "trailingComma": "none"
27      }
28    }
29  ]
30}
31```
32
33## JSON Language Server
34
35Zed automatically out of the box supports JSON Schema validation of `package.json` and `tsconfig.json` files, but `json-language-server` can use JSON Schema definitions in project files, from the [JSON Schema Store](https://www.schemastore.org) or other publicly available URLs for JSON validation.
36
37### Inline Schema Specification
38
39To specify a schema inline with your JSON files, add a `$schema` top level key linking to your json schema file.
40
41For example to for a `.luarc.json` for use with [lua-language-server](https://github.com/LuaLS/lua-language-server/):
42
43```json
44{
45  "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
46  "runtime.version": "Lua 5.4"
47}
48```
49
50### Schema Specification via Settings
51
52You can alternatively associate JSON Schemas with file paths by via Zed LSP settings.
53
54To
55
56```json
57"lsp": {
58  "json-language-server": {
59    "settings": {
60      "json": {
61        "schemas": [
62          {
63            "fileMatch": ["*/*.luarc.json"],
64            "url": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json"
65          }
66        ]
67      }
68    }
69  }
70}
71```
72
73You can also pass any of the [supported settings](https://github.com/Microsoft/vscode/blob/main/extensions/json-language-features/server/README.md#settings) to json-language-server by specifying them in your Zed settings.json:
74
75<!--
76TBD: Add formatter (prettier) settings (autoformat, tab_size, etc)
77-->