AppCode 2021.2 Help

JSON

The JSON format is commonly used for storing data and for configuration files. AppCode helps you work with JSON files — it checks their syntax and formatting. In popular types of configuration files, AppCode provides code completion, thanks to the JSON Schema, which is a special format for describing the structure and contents of such files. You can also use custom JSON Schemas to enable code completion in your JSON files and validate them.

Enabling JSON5

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

JSON5 file in the editor

Extend the JSON5 syntax to all JSON files

  1. In the Preferences dialog ⌃ ⌥ 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.

Using schemas from JSON Schema Store

AppCode 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, tslint.json), AppCode 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 or click New Schema Mapping to open the JSON Schema Mappings page and configure a new custom schema.

No JSON schema for the current file

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

Enable automatic download schemas from the JSON Schema Store

  1. In the Preferences dialog ⌃ ⌥ S, go to Languages and 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.

AppCode 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 Preferences dialog ⌃ ⌥ S, go to Languages and Frameworks | Schemas and DTDs | Remote JSON Schemas.

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

Using custom JSON schemas

Besides schemas from JSON Schema Store, AppCode lets you configure and use custom schemas from other storages. You can download the required schema and store it under the project root or specify the URL of the resource so AppCode can download the schema automatically.

Configure a custom JSON Schema

  1. In the Preferences dialog ⌃ ⌥ S, go to Languages and Frameworks | Schemas and DTDs | JSON Schema Mappings.

  2. In the central pane, that shows all your previously configured custom Schemas, click Add on the toolbar.

  3. Specify the name of the Schema and the Schema Specification version with which your Schema complies. In the Schema file or URL field, specify the location of a previously downloaded Schema file or type the URL at which the required schema is available.

  4. Create a list of files or folders that you want to be validated against this Schema. The list may contain the names of specific files, the names of entire directories, and filename patterns. Based on the list, AppCode internally detects the files to be validated.

    To add an item to the list, click Add mapping and specify the path to a file or folder or type a file pattern.

Enable automatic download of JSON schemas from remote sources

  1. In the Preferences dialog ⌃ ⌥ S, go to Languages and 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.

Conflicts among scopes of schemas

When you are trying to map one file to different JSON schemas in Preferences | Languages & Frameworks | Schemas and DTDs | JSON Schema Mappings, the following warning will appear:

Notification about conflicting schema scopes in Preferences dialog

Using HTML descriptions in JSON schema

By default, AppCode escapes HTML characters when displaying documentation for JSON schema definitions in documentation popups. 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": "http://json-schema-org/draft-06/schema#", "type": "object", "required": [ "options" ], "properties": { "options": { "type": "array", "description": "Interesting details: Fresh New Awesome", "minItems": 1, "items": { "type": "string" }, "uniqueItems": true, }, "readonly": { "type": "boolean" } } }
No formatting in documentation for JSON schema definitions with description property
{ "id": "http://some.site.somewhere/entry-schema#", "$schema": "http://json-schema-org/draft-06/schema#", "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" } } }
HTML descriptions in documentation for JSON schema definitions with x-intellij-html-description property

Configuring syntax highlighting

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

  1. In the Preferences dialog ⌃ ⌥ 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: 20 May 2021