JSON, JSON Schema
JSON (JavaScript Object Notation) is a lightweight data storage and interchange format that uses JavaScript syntax, and, like XML, is a human-readable, text-only format. Since JSON text can be read and used by any programming language, it has come to be used widely as a data exchange format, especially on the web.
As part of its IDE functionality, XMLSpy provides support for the editing and validation of JSON data documents (instance documents) and for the creation of syntactically and semantically correct JSON Schema documents.
XMLSpy also provides support for Avro and Avro Schema.
JSON5
JSON5 is an extension of JSON that adds some ECMAScript 5 extensions (see json5.org for more information). JSON5 is a strict subset of JavaScript, adds no new data types to existing JSON types, and works with all existing JSON content.
All XMLSpy functionality that is available for JSON instance documents is also available for JSON5 instance documents. However, note the following major differences between JSON5 and JSON, and in the way XMLSpy handles the two formats:
•JSON5 is not an official successor to JSON. It therefore uses its own file extension: json5.
•By default, XMLSpy recognizes files with the .json file extension as JSON instance documents, and those with the .json5 file extension as JSON5 instance documents.
•JSON5 instance documents can be validated against JSON schemas. JSON instance documents, which can be representations of Avro instances, can be validated against both JSON schemas and Avro schemas. See the section Validating JSON Documents for more on this topic.
In this documentation, the term JSON instances refers to both JSON and JSON5 instance documents unless otherwise indicated. Also see the section Differences between JSON5 and JSON.
JSON and JSON Schema in XMLSpy
Both document types—JSON instance and JSON schema—are written in JSON format, and must adhere to JSON rules of well-formedness and validity. Both types of document (instance and schema) typically have the .json file extension. JSON instances can be edited in Text View and Grid View, and JSON schema documents can be edited in those two views as well as in JSON Schema View, which is a graphical schema editor.
XMLSpy provides the following support for working with JSON instance and JSON schema documents:
•In Text View, syntax coloring and syntax checks; auto-completion in JSON schemas and in instance documents if these have schema associations, folding margins; and structural markings. All of these features ease and speed up the editing of valid JSON instance and JSON schema documents. Text View provides validation of both instance and schema documents.
•In Grid View, a tabular grid structure that helps to better visualize document structure. You can edit directly in Grid View. You can also switch between Text View and Grid View to suit your editing needs. Grid View provides validation of both instance and schema documents.
•JSON instance document validation in Text View and Grid View. The validation is carried out against a JSON schema that is assigned in the Info Window.
•JSON Schema View displays JSON schemas in a graphical layout. This enables the use of drag-and-drop functionality (in addition to text entry) for the quick creation of JSON schemas. Entry helpers within the view provide editing input. Additionally, the schema is continuously checked for validity, and errors are flagged.
JSON instances: opening existing instance documents and creating new instance documents
•In the Options | File types section, you can set the default view (Text View or Grid View) for opening JSON/JSON5 instance documents. Existing JSON/JSON5 documents will be opened in the default starting view you select. You can switch between Text View and Grid View at any time.
•To create a new JSON or JSON5 instance document, click File | New, and select, respectively, json: JavaScript Object Notation or json5: JSON with ECMAScript 5 extensions. You will be prompted to optionally choose a JSON or (for JSON, not JSON5) Avro schema file for the new instance file. If you assign a schema, the assignment will be entered in the Info Window. The new instance document will be opened in Text View or Grid View, depending on the settings in the Options | File types tab.
JSON schemas: opening existing schemas and creating new schemas
•An existing JSON schema document opens in JSON Schema View. You can switch to Text View or Grid View at any time.
•To create a new JSON schema document, click File | New, and select json: JSON Schema. The new JSON schema document will be opened in JSON Schema View, with the \$schema keyword at the start of the document. You can switch to Text View or Grid View at any time.
All these views (Text, Grid, and JSON Schema) are described in the sub-sections of this section.
In this section
This section is organized into the following topics:
•JSON Data explains the basics of JSON documents
•JSON Schema describes what a JSON schema is and how it works
•JSON Lines and JSON Comments provides information about two additional JSON specifications supported by XMLSpy
•JSON Documents in Text View shows you how to work with the JSON-relevant features of Text View
•JSON Documents in Grid View describes how to edit JSON documents in Grid View
•JSON Schema View explains the JSON-schema-editing features of the view and how you can use it when creating your JSON projects
•Validating JSON Data/Documents describes how to assign a JSON schema to a JSON document and how to validate JSON documents
•Inserting JSON Fragments describes how to quickly insert JSON text fragments into your JSON document from external sources
•JSON Transformations with XSLT/XQuery describes how JSON documents can be queried with XPath/XQuery 3.1
•XQuery Expressions for JSON gives a broad introduction about using XQuery with JSON documents
•Generating JSON Schema from a JSON Instance describes the functionality to generate a schema from an instance
•Generating a JSON Instance from a JSON Schema describes how to generate an instance from a schema
•Converting between JSON and XML describes how to convert between JSON and XML in XMLSpy