JSON
The JSON format is commonly used for storing data and for configuration files. IntelliJ IDEA helps you work with JSON files — it checks their syntax and formatting. In popular types of configuration files, IntelliJ IDEA 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.
IntelliJ IDEA 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.
Enable JSON5
IntelliJ IDEA recognizes a number of most popular JSON standards, including JSON5. IntelliJ IDEA by default treats files with the json5 extension as JSON5 files and supports this new syntax in them.
Extend the JSON5 syntax to all JSON files
In the Settings dialog (Ctrl+Alt+S) , go to .
In the Recognized File Types list, select JSON5.
In the File Name Patterns area, click and type
*.json
in the Add Wildcard dialog that opens.
Use schemas from JSON Schema Store
IntelliJ IDEA 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), IntelliJ IDEA downloads and uses this schema for it. The name of the applied schema is shown on 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. IntelliJ IDEA 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.
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
In the Settings dialog (Ctrl+Alt+S) , go to .
Select the Allow downloading JSON schemas from remote sources and the Use schemastore.org JSON Schema catalog checkboxes.
IntelliJ IDEA 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
In the Settings dialog (Ctrl+Alt+S) , go to .
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, IntelliJ IDEA 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 IntelliJ IDEA can download the schema automatically.
Custom schemas must meet the JSON schema standards. Currently, IntelliJ IDEA supports schemas 2020-12 and earlier.
Create a custom JSON schema association
In the Settings dialog (Ctrl+Alt+S) , go to .
Alternatively, click No JSON Schema on the Status bar and then select New Schema Mapping. In this case, IntelliJ IDEA will automatically include the file in the list of associated files, folders, and patterns.
In the central pane, that shows all your previously configured Schemas, click on the toolbar and specify the name of the mapping.
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 the Schema Specification version with which your Schema complies.
Create a list of files or folders that you want to be validated against this Schema. Based on the list, IntelliJ IDEA 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 withrole-
.role-*/**/*.yaml
matches all .yaml files with names that containrole
,/
, and/
.role-**.yaml
matches all .yaml files with names that start withrole-
.
To add an item to the list, click .
Specify the path to a file or folder or type a file pattern. Specify paths relative to the project root.
Enable automatic download of JSON schemas from remote sources
In the Settings dialog (Ctrl+Alt+S) , go to .
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.
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.
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.
To disable a custom schema for the whole of the current project, open the Settings dialog (Ctrl+Alt+S) , go to , select the schema assotiation in the central pane, and click 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, IntelliJ IDEA 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.
On the JSON Schema Mappings page of the Settings dialog, a warning is shown when the scopes of several mappings overlap.
Use HTML descriptions in JSON schema
By default, IntelliJ IDEA escapes HTML characters when displaying documentation for JSON schema definitions in documentation popups.
Suppose, your schema uses the description
property:
Then the Quick Documentation popup will look as follows:
To get nice looking documentation with rich HTML markup, store the HTML description in the x-intellij-html-description
extension property instead of description
:
Now the Quick Documentation popup looks as follows:
Configure syntax highlighting
You can configure JSON-aware syntax highlighting according to your preferences and habits.
In the Settings dialog (Ctrl+Alt+S) , go to .
Select the color scheme, accept the highlighting settings inherited from the defaults or customize them as described in Colors and fonts.