VideosJSON Validation Support

Overview

Duration: 06:05
This demonstration shows several techniques and features for working with JSON documents in a more productive way.

Transcript

00:00:09Starting with version 20.1, Oxygen improved the JSON support by adding the ability to
00:00:14validate JSON documents against a JSON schema and also to validate JSON schemas according
00:00:22to the specification.
00:00:23In this demonstration, I will show you these improvements in detail while working with
00:00:29a set of JSON documents and schemas.
00:00:32First I'll open a JSON document...
00:00:35I immediately notice that the file contains an error...
00:00:39This is a syntax error that was triggered by the default JSON wellformedness scanner.
00:00:46This scanner detects errors automatically as you type, highlighting them in the document.
00:00:53You can also invoke the Check Wellformedness action manually from the Validation menu and
00:00:59you will see all the reported errors in the Problems view below the editor area.
00:01:05In my case, correcting the problem simply involves inserting the closing bracket for
00:01:10the "name" object along with a comma separator.
00:01:17Note that more Validation actions are available in the Validation dropdown menu.
00:01:25You can add more constraints to your JSON document by validating it against a JSON schema.
00:01:32My project already contains such a schema... so I'll open it.
00:01:37This schema defines the structure of the document and adds some constraints.
00:01:43For example, the schema architect wanted each "person" object to contain the following information:
00:01:49id, name, email, and a link to that person's manager.
00:01:55Note that for the email property, a built-in email format check is applied.
00:02:01For the "name" property, a "nameType" is defined...
00:02:05In this example, the name must contain a "family" and a "given" property and their values are
00:02:11enforced by a set of constraints defined in the "nameValueType".
00:02:16Also, each name value needs to contain only letters and should not exceed 20 characters.
00:02:25Back to my JSON document...
00:02:28To check if it conforms with the rules defined in the JSON schema,
00:02:34I can use the "Validate with" action.
00:02:36I set the URL to point to the JSON schema, then execute the validation.
00:02:43Notice that there are two errors that violate the rules defined in the JSON schema: the
00:02:48family name contains an invalid character and there's an incorrect email address.
00:02:56Using the 'Validate with' action to validate against a JSON schema is on-demand, so if
00:03:02you perform any modifications to your document,
00:03:06you need to invoke the validation operation again.
00:03:08Notice that the errors are displayed in the Problems view below the editor, but they are
00:03:14not highlighted in the editor
00:03:18To benefit from the automatic, continuous
00:03:21validation support, you can associate the JSON schema with the JSON document through
00:03:26a validation scenario.
00:03:28For this, you need to use the "Configure Validation Scenario(s)" action from the "Validation"
00:03:33menu ... create a new validation scenario for the
00:03:36JSON document ... and specify the JSON Schema to validate
00:03:41against (in my case it's the "personalSchema.json")
00:03:47Now the document is validated against the JSON schema automatically as you type and
00:03:53the errors will be highlighted in the document.
00:04:01Oxygen also offers support for validating JSON schemas.
00:04:07If a JSON document has the "$schema" property on the root, it will be validated as a JSON
00:04:14Schema according to the version specified in the value of the property.
00:04:18I will create an error by changing a type reference.
00:04:24After validating, the error is presented in the results view.
00:04:29The Validation support for the JSON schema is similar to that offered for JSON documents:
00:04:35Check well-formedness, Validate with, Validation scenarios, Validation as you type.
00:04:43Note that if a schema does not have the "$schema" property set on the root,
00:04:47it will only be checked for well-formedness.
00:04:52However, you can validate it as a schema file if you create a validation scenario and specify
00:04:59the "JSON Schema Validator" as validation engine.
00:05:08This means that the schema errors will be presented even if the "$schema" property is
00:05:12not specified on the root.
00:05:18Also, multiple JSON files can be validated from the contextual menu in the Project view.
00:05:29To create a JSON document or JSON Schema from scratch,
00:05:34you can use the built-in new file templates.
00:05:38for JSON Schema, you can even specify the version of the schema that you want to create.
00:05:45These validation features are helping you getting more productive:
00:05:49your JSON documents are always kept valid and consistent with the specifications.
00:05:55This concludes my demonstration.
00:05:58Thank you for watching.

Use Oxygen Feedback to ask us anything about this video.