The JSON format is commonly used for storing data and for configuration files. WebStorm helps you work with JSON files - it checks their syntax and formatting. In popular types of configuration files, WebStorm provides code completion, thanks to the JSON Schema support. You can also use custom JSON Schemas to enable code completion in your JSON files and validate them.
WebStorm recognizes all JSON standards including JSON5. By default, you can use this new syntax only in files with the json5 extension, but you can extend it to all json files.
- In the Settings/Preferences dialog (Ctrl+Alt+S), click File Types under Editor. The File Types page opens.
- In the Recognized File Types list, select JSON5.
- In the Registered Patterns area, click and type
*.jsonin the Add Wildcard dialog that opens.
Using JSON schemas
WebStorm validates JSON files and provides code completion in them using JSON Schema, which is a special format for describing the structure and contents of such files.
WebStorm 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, composer.json), WebStorm 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, click the schema name on the Status bar and select the required schema from the list.
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.
To enable automatic download of Schemas from the JSON Schema Store
- In the Settings/Preferences dialog (Ctrl+Alt+S), click Schemas and DTDs under Languages and Frameworks, and then click Remote JSON Schemas.
- On the Remote JSON Schemas page that opens, select the Allow downloading JSON schemas from remote sources and the Use schemastore.org JSON Schema catalog checkboxes.
To use a custom JSON Schema
- In the Settings/Preferences dialog (Ctrl+Alt+S), click Schemas and DTDs under Languages and Frameworks, and then click JSON Schema Mappings. The JSON Schema Mappings page opens.
- In the central pane, that shows all your previously configured custom Schemas, click on the toolbar.
- 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.
- Create a list of files or folders that you want to be validated against this Schema. To add an item to the list, click and specify the path to a file or folder or type a file pattern.