Altova XMLSpy 2024 Professional Edition

Create and Validate YAML Documents

Home Prev Top Next

Create YAML documents

In XMLSpy, the .yaml and .yml file extensions have been defined as YAML file extensions. If you wish to add other file extensions for your YAML documents, then do this in the File Types section of the Options dialog. XMLSpy will treat documents with YAML file extensions as a YAML document and will enable XMLSpy's YAML viewing and editing features for these documents.

 

When a new YAML file is created with File | New, you will be asked if you want to assign a JSON schema to the YAML file.

 

If you assign a JSON schema (see "Validate YAML documents" below), then the new file will be created with a sample YAML document and displayed in a new window.

If you choose not to assign a JSON schema, then an empty YAML document is created in a new window. If you subsequently assign a JSON schema to the empty YAML document, then a sample YAML document based on the JSON schema is generated in the empty YAML document.

 

Validate YAML documents

YAML documents can be validated against JSON Schemas.

 

Set the JSON Schema for validation

To set the JSON schema against which you want to validate a JSON or 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. (Note that Avro support is available in XMLSpy Enterprise Edition only.)

JSONInfoWindow

Note that the JSON schema assignment is not written into the JSON or YAML document, but entered in the Info window of XMLSpy. When you now validate the JSON or YAML document, the JSON schema file in the Info window will be the file used for validation.

 

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 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 validation separately, then we recommend that you put each document type in a separate project subfolder.

 

For information about generating a JSON schema from a YAML document, see Generate JSON Schema from YAML Document.

 

Validate the document

After setting the JSON schema for validation, validate the document by selecting the command Validate (F8, XML | Validate). If you want to be informed about the validity of your document as you type, toggle on the Validate on Edit feature (XML | Validate on Edit). Validation results will be highlighted in the document and details will be displayed in the Messages window. You can click an error in the Messages window to go to that error in the document.

 

© 2018-2024 Altova GmbH