{"id":94,"date":"2018-10-08T14:23:00","date_gmt":"2018-10-08T14:23:00","guid":{"rendered":"https:\/\/www.json-buddy.com\/blog\/?p=94"},"modified":"2022-10-18T14:25:32","modified_gmt":"2022-10-18T14:25:32","slug":"json-editor-in-a-nutshell-how-to-assign-a-json-schema","status":"publish","type":"post","link":"https:\/\/www.json-buddy.com\/blog\/2018\/10\/08\/json-editor-in-a-nutshell-how-to-assign-a-json-schema\/","title":{"rendered":"JSON editor in a nutshell: How to assign a JSON schema"},"content":{"rendered":"\n<p>The JSON schema specification defines no way to assign a schema to a JSON data file. The schema used for validation is either set by the application or by any meta-data like transmission headers or even filename patterns. As an editor for JSON schema, <a href=\"https:\/\/www.json-buddy.com\" target=\"_blank\" rel=\"noopener\">JSONBuddy<\/a> needs to support methods to assign a JSON schema to the JSON data you are currently working on. Here are some ways to set the schema for your data:<\/p>\n\n\n\n<h3>Assign a local schema file using the &#8220;Quick associations&#8221; pane<\/h3>\n\n\n\n<p>The most straightforward way is to use the &#8220;Quick associations&#8221; pane of the editor to select a local JSON schema file from disk for the current document. This assignment is saved and restored the next time you open the instance in the JSON editor.<\/p>\n\n\n\n<h3>Open a JSON schema from schemastore.org and automatically generate sample data<\/h3>\n\n\n\n<p>This method is explained in more detail in <a href=\"https:\/\/www.json-buddy.com\/blog\/2018\/04\/06\/all-your-json-schema-are-belong-to-us\/\" target=\"_blank\" rel=\"noopener\">this article<\/a>. You can use the &#8220;Open from JSON schema library&#8230;&#8221; dialog in the editor to automatically generate sample data from any schema available at schemastore.org. The schema is also assigned to the generated JSON instance.<\/p>\n\n\n\n<h3>The file-name is matching a specific pattern<\/h3>\n\n\n\n<p>A lot of entries in the JSON schema library available at schemastore.org are also defining a file-name pattern which is used to load a schema from the library to validate the JSON data. For example, if you load a JSON document with the name &#8220;test.bower.json&#8221; the data is recognized as &#8220;Bower package description file&#8221; and you get the following message in the results window of the editor:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.json-buddy.com\/blog\/wp-content\/uploads\/2018\/10\/schemastore-filename-pattern-example.png\" alt=\"\" class=\"wp-image-243\"\/><figcaption>Automatically assigned Bower schema from schemastore.org<\/figcaption><\/figure>\n\n\n\n<h3>Generate sample data from any JSON schema<\/h3>\n\n\n\n<p>As a quick way to get a JSON instance from any schema use the <a href=\"https:\/\/www.json-buddy.com\/blog\/2018\/08\/29\/using-the-built-in-json-schema-generator\/\" target=\"_blank\" rel=\"noopener\">command to generate sample JSON data<\/a>. This way a new document is created in the editor and the source schema is also assigned in a single step.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The JSON schema specification defines no way to assign a schema to a JSON data file. The schema used for validation is either set by the application or by any meta-data like transmission headers or even filename patterns. As an editor for JSON schema, JSONBuddy needs to support methods to assign a JSON schema to &hellip; <a href=\"https:\/\/www.json-buddy.com\/blog\/2018\/10\/08\/json-editor-in-a-nutshell-how-to-assign-a-json-schema\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">JSON editor in a nutshell: How to assign a JSON schema<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[4],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/posts\/94"}],"collection":[{"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":2,"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/posts\/94\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.json-buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}