Altova XMLSpy 2025 Enterprise Edition

Validate JSON Documents

Home Prev Top Next

XMLSpy contains a JSON validation engine that can be invoked to do the following:

 

If a JSON schema is the active document: Validates the JSON schema against the appropriate JSON Schema specification; the schema version is indicated by the $schema keyword; the validation can be carried out in any of the three views (Text, Grid, and JSON Schema).

If a JSON instance is the active document: Validates the JSON instance against a JSON schema. The schema is assigned to the JSON instance as described below. JSON instance validation can be carried out in Text View and Grid View.

If a JSON5 instance is the active document: Validates the JSON instance against a JSON schema. The schema is assigned to the JSON5 instance as described below. JSON5 instance validation can be carried out in Text View and Grid View.

 

Avro validation (Enterprise Edition only)

Avro data and Avro schema documents, as JSON documents, can be validated in Text View and Grid View:

 

If an Avro data instance in JSON format is the active document: Validates the Avro instance against an Avro schema. The schema is assigned to the instance as described below.

If an Avro schema is the active document: Validates the Avro schema against the Avro schema specification (no schema assignment is needed); the validation can be carried out in Text View or Grid View.

 

Assign a JSON or Avro schema to a JSON instance

JSON instance documents can be validated against a JSON schema or Avro schema.

 

To set the JSON schema against which you want to validate a JSON/YAML document, do the following:

 

1.Make the JSON/YAML document the active document.

2.In the JSON tab of the Info window (screenshot below), click the arrow icon next to Validation against schema, and, in the menu that appears, click Select JSON Schema. For validating YAML documents, you can select a JSON schema that is written in either JSON format or YAML format, but not an Avro schema.

JSONInfoWindow

Note that the JSON schema assignment is not written into the JSON or YAML document, but entered in the Info window (see screenshot above) and used for validation in XMLSpy.

 

To remove the assignment, select the command Remove Schema from the same menu (see screenshot above).

 

Note:If the JSON or YAML file is part of an XMLSpy project, then the JSON or Avro schema for validation can also be assigned via the Project Properties dialog (use the Validate With option in this dialog). If you then validate a project folder, all the JSON and YAML files in the project folder will be validated against the JSON schema. If you wish to run JSON and YAML validations separately, then we recommend that you put each document type in a separate project subfolder.

 

For information about generating a JSON schema from the JSON instance, see the section Generating JSON Schema from a JSON Instance.

 

Validate instance and schema documents

Select the command XML | Validate XML (F8) or click the Validate (F8) icon ic_validate in the toolbar to validate the active JSON document (instance or schema) or Avro schema. If an instance document is being validated, a schema document must be assigned to the instance (see above). Validation results are displayed in the Messages window. Errors are also flagged in the line-numbering margin. If a smart fix is available for an error, then a light bulb icon is shown on the line that generates the error. When you place the mouse over the icon, a popup appears that lists available smart fixes. Select a fix to apply it immediately.

Note:The validation error indicators and smart fixes described above are refreshed only when the XML | Validate (F8) command is executed; they are not updated in the background. So, after correcting an error, you must run the Validate (F8) command again to make sure that the error has indeed been fixed.

 

To go to the schema document from the instance document, double-click the schema in the Info window (see screenshot above), or select the command DTD/Schema | Go to Schema. To go directly to the schema definition of a JSON keyword or object, select the keyword or object in the instance document and select DTD/Schema | Go to Definition.

 

You can also validate a project folder containing JSON files by using the Validate command.

 

Validate on modification

The Validate on Edit mode is toggled on by default. When toggled on, well-formed checks and validation checks are carried out as you modify a document in Text View or Grid View. For validation of a JSON/YAML document to be carried out (additional to well-formed checks), a JSON schema must be assigned to the JSON document. Errors are shown by displaying erroneous text in red and flagging the location with a red exclamation mark. See Validating JSON Documents and Validating YAML Documents for more information.

 

The Validate on Edit mode can be toggled on/off either (i) via the XML | Validate on Edit menu command, (ii) the Validate on Edit toolbar button, or (iii) via the On Edit option of the Validation settings of the Options dialog.

 

© 2018-2024 Altova GmbH