GoLand 2024.3 Help

JSON

The JSON format is commonly used for storing data and for configuration files. GoLand helps you work with JSON files — it checks their syntax and formatting. In popular types of configuration files, GoLand validates code and provides code completion based on the JSON Schema, which is a special format for describing the structure and contents of such files.

GoLand comes bundled with a set of registered schemas for most popular formats. You can also use schemas from the JSON Schema Store or custom JSON schemas.

Bundles schemas and schemas from Schema Store

Enable JSON5

GoLand recognizes a number of most popular JSON standards, including JSON5. GoLand by default treats files with the json5 extension as JSON5 files and supports this new syntax in them.

Configuration file that uses JSON5 with the default extension .json5

Extend the JSON5 syntax to all JSON files

  1. In the Settings dialog (Ctrl+Alt+S) , go to Editor | File Types.

  2. In the Recognized File Types list, select JSON5.

  3. In the File Name Patterns area, click Add and type *.json in the Add Wildcard dialog that opens.

    Extend the JSON5 syntax to all JSON files

Use schemas from JSON Schema Store

GoLand can automatically download and use schemas from the JSON Schema Store that hosts schema files for many popular configuration files. As soon as you open a file whose name is associated with one of the available schemas (for example, tsconfig.json), GoLand downloads and uses this schema for it. The name of the applied schema is shown on the Status bar.

JSON schema downloaded from JSON Schema Store, the name of the applied schema is shown in the Status bar

If your configuration file has a custom name, or you are working with a scratch file, click No JSON schema on the Status bar and select the required schema from the list. GoLand associates the current file with the selected schema and adds this schema mapping to the list on the JSON Schema Mappings page.

Alternatively, click New Schema Mapping to open the JSON Schema Mappings page and configure a new schema association.

No JSON schema for the current file

By default, automatic download of Schemas from the JSON Schema Store is enabled. If it was turned off, you can enable it again at any time.

Download schemas from the JSON Schema Store automatically

  1. In the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | Schemas and DTDs | Remote JSON Schemas.

  2. Select the Allow downloading JSON schemas from remote sources and the Use schemastore.org JSON Schema catalog checkboxes.

GoLand comes bundled with a number of popular schemas. Although these schemas are automatically updated on a regular basis they still may happen to be outdated.

Use the up-to-date versions of bundled schemas

  1. In the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | Schemas and DTDs | Remote JSON Schemas.

  2. Select the Always download the most recent version of schemas checkbox.

Use custom JSON schemas

Besides bundled registered schemas and schemas from JSON Schema Store, GoLand lets you create your own ones or use custom schemas from other storages. You can create or download the required schema and store it under the project root or specify the URL of the resource so GoLand can download the schema automatically.

Custom schemas must meet the JSON schema standards. Currently, GoLand supports schemas 2020-12 and earlier.

Custom schema meets the 2020-12 standard

Create a custom JSON schema association

  1. In the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | Schemas and DTDs | JSON Schema Mappings.

    Alternatively, click No JSON Schema on the Status bar and then select New Schema Mapping. In this case, GoLand will automatically include the file in the list of associated files, folders, and patterns.

  2. In the central pane, that shows all your previously configured Schemas, click Add on the toolbar and specify the name of the mapping.

  3. In the Schema file or URL field, specify the location of a previously created or downloaded Schema file or the URL at which the required schema is available. The name pf the Schema file or the corresponding URL address appears in the Schema file or URL field.

    Specify a Schema file
  4. Specify the Schema Specification version with which your Schema complies.

    Select the Schema version
  5. Create a list of files or folders that you want to be validated against this Schema. Based on the list, GoLand internally detects the files to be validated.

    The list may contain the names of specific files, the names of entire directories, and file name patterns. Use the following rules to specify file name patterns:

    • role-* matches all files with the names that start with role-.

    • role-*/**/*.yaml matches all .yaml files with names that contain role, /, and /.

    • role-**.yaml matches all .yaml files with names that start with role-.

    To add an item to the list, click Add mapping.

    Add an item to the scope

    Specify the path to a file or folder or type a file pattern. Specify paths relative to the project root.

    Specify file pattern

Enable automatic download of JSON schemas from remote sources

  1. In the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | Schemas and DTDs | Remote JSON Schemas.

  2. Select the Allow downloading JSON schemas from remote sources.

    When the checkbox is cleared, any network activity around JSON Schemas, including schemas from the JSON Schema Store, is disabled.

Disable JSON schemas

  • To disable a schema for a file, click the JSON Schema widget on the Status bar and then select Ignore JSON schema for file from the popup list.

    Ignore Schema for the current file

    Alternatively, select Edit Schema Mappings and edit the scope of the schema. For example, you can edit the appropriate pattern or remove the file from the list if the file name is specified explicitly.

    Finally, you can select New Schema Mapping and configure a schema association, as described above.

    Ignore schema and create new mapping
  • To restore association with a schema for the current file, click No JSON Schema on the Status bar and select Stop Ignoring JSON Schema for file from the popup list.

    Restore association with schema for a file
  • To disable a custom schema for the whole of the current project, open the Settings dialog (Ctrl+Alt+S) , go to Languages & Frameworks | Schemas and DTDs | JSON Schema Mappings, select the schema assotiation in the central pane, and click the Delete button on the toolbar.

Handle conflicts among scopes of schemas

If a file, a folder, or a pattern belongs to the scopes of two or more schemas, GoLand detects this conflict and displays a warning in the editor and on the JSON Schema Mappings page of the Settings dialog.

In the editor, a warning is shown when you open a file that belongs to several scopes.

Notification about conflicting schema scopes in the editor

On the JSON Schema Mappings page of the Settings dialog, a warning is shown when the scopes of several mappings overlap.

Notification about conflicting schema scopes in the Settings dialog

Use HTML descriptions in JSON schema

By default, GoLand escapes HTML characters when displaying documentation for JSON schema definitions in documentation popups.

Suppose, your schema uses the description property:

{ "id": "http://some.site.somewhere/entry-schema#", "$schema": "https://json-schema.org/draft/2020-12/json-schema-core", "type": "object", "required": [ "options" ], "properties": { "options": { "type": "array", "description": "Interesting details: Fresh New Awesome", "minItems": 1, "items": { "type": "string" }, "uniqueItems": true }, "readonly": { "type": "boolean" } } }

Then the Quick Documentation popup will look as follows:

No formatting in documentation for JSON schema definitions with description property

To get nice looking documentation with rich HTML markup, store the HTML description in the x-intellij-html-description extension property instead of description:

{ "id": "http://some.site.somewhere/entry-schema#", "$schema": "https://json-schema.org/draft/2020-12/json-schema-core", "type": "object", "required": [ "options" ], "properties": { "options": { "type": "array", "x-intellij-html-description": "<p><b>Interesting</b> <i>details:</i></p>\n <ul><li>Fresh</li><li>New</li><li>Awesome</li></ul>\n <div style='background-color: #fff77c'>Choose schema with HTML description =)</div>", "minItems": 1, "items": { "type": "string" }, "uniqueItems": true }, "readonly": { "type": "boolean" } } }

Now the Quick Documentation popup looks as follows:

HTML descriptions in documentation for JSON schema definitions with x-intellij-html-description property

Configure syntax highlighting

You can configure JSON-aware syntax highlighting according to your preferences and habits.

  1. In the Settings dialog (Ctrl+Alt+S) , go to Editor | Color Scheme | JSON.

  2. Select the color scheme, accept the highlighting settings inherited from the defaults or customize them as described in Colors and fonts.

Last modified: 08 December 2024