Adding a JSON Schema Validator in IntelliJ
This guide walks you through the process of adding a JSON Schema validator in IntelliJ to enhance your JSON file validation and auto-completion.
Step 1: Open IntelliJ Preferences
- Open IntelliJ.
- Navigate to File > Settings (or IntelliJ IDEA > Preferences on macOS).
Step 2: Navigate to JSON Schema Settings
- In the settings menu, search for JSON Schema in the search bar.
- Click on Languages & Frameworks > Schemas and DTDs > JSON Schema Mappings.
Step 3: Add a New JSON Schema
- Click the + icon to add a new schema.
- Choose Schema File and select one of the following options:
- From File: If you have a local schema file, navigate to and select it.
- From URL: If the schema is hosted online, enter the URL.
- Built-in Schema: Select from IntelliJ's built-in options.
Step 4: Map the Schema to Your Files
- Under Mapped Patterns, click the + icon.
- Add the file pattern or directory for which the schema should apply. For example, to apply the schema to all
config.json
files, addconfig.json
as a pattern. - You can also use wildcard patterns like
.*\.(json|yaml|yml|JSON)$
or specify a folder likesrc/config/*.json
.
Step 5: Validate and Apply Changes
- Click OK to save the schema configuration.
- Open a JSON file to ensure IntelliJ is validating it against the schema. You should see:
- Auto-completion suggestions.
- Error messages for invalid fields or types.