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 (for which no additional schema assignment is needed); 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)
|•||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.|
Assigning a JSON schema to a JSON instance
In order to validate a JSON instance against a JSON schema, the schema must be assigned to the active instance document. The assignment is entered in the Info window (screenshot below; Avro support is available in the Enterprise edition only) of the active JSON instance document, or via the Project Properties dialog (the Validate With option). Note that JSON5 instance documents are validated against JSON schemas.
In the JSON tab of the Info Window, click the arrow icon next to Validation against schema, and, in the menu that appears, click Select JSON Schema (see screenshot above; Avro support is available in the Enterprise edition only). For JSON5 instance documents only the JSON schema option is enabled. Browse for the schema, and click OK. The schema will be assigned to the active JSON instance document, and the schema's filename will be entered in the Info window. If the JSON instance document is empty, the assignment of a JSON schema to the instance will automatically fill the JSON instance with sample data based on the schema.
To remove the assignment, select the command Remove Schema from the same menu (see screenshot above).
For information about generating JSON schema from the JSON instance, see the section Generating JSON Schema from a JSON Instance.
Validating instance and schema documents
Select the command XML | Validate XML (F8) or click the Validate (F8) icon in the toolbar to validate the active JSON document (instance or 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.
© 2019 Altova GmbH