JSON Schema in the wild: A missing required property

There are some issues that happen over and over again if you write JSON schemas with a plain text editor. You can often follow them in the Slack community for JSON schema or at StackOverflow: A schema is modified and the validation is no longer working as before but nobody knows about it at the time the schema was changed.

The good news is: The built-in JSON schema analyzer in JSONBuddy can detect a lot of those issues while you are editing your schema in the JSON editor.

A while ago this happened to a user: A property was removed from the JSON Schema but was still present in the “required” keyword array. As a consequence, a lot of the JSON data was invalid.

Use an extraordinary JSON schema editor

This can’t happen if you use JSONBuddy as your JSON schema editor. Because the built-in schema analyzer reports the missing required property definition right at the time when you are editing your schema. Instead, you get the following warning:

Warning about a missing required property.

This and several other common issues are reported by the schema analyzer if you use JSONBuddy as your JSON schema editor. Providing you with exceptional support when working with JSON Schema documents helps to save time and avoid extra work.

JSON editor and validator for large schemas

Sometimes it can happen that a JSON schema is generated from existing data and the resulting schema is quite huge. And maybe this schema is just taken as a starting point and you need to extend or modify it to get the final specifications for your JSON input.

One example of a really huge JSON schema is the Ansible schema available from schemastore.org (Please take a look at this blog entry to see how easy it is to open any schema from schemastore.org in JSONBuddy). The Ansible schema has currently more than 100.000 lines and 5 MB of JSON text. For this task, you need a good JSON editor which can also handle quite large files.

JSONBuddy: The editor for large JSON schemas

JSONBuddy is capable of loading big schema documents. The editor will apply syntax-coloring, entry-helpers and code folding as it does for a typical schema. You also don’t have to work on your schema without the context-sensitive help of getting the specification text for the keyword you are currently editing. All of this is also functional for big schemas.

But there is more. For example, besides being able to edit a JSON schema as you are used to, you get an instant evaluation from the built-in JSON schema analyzer. The schema analyzer runs in the background and is also active for large schema documents. For example, if a certain definition is not used in the local schema, there is no need to run an explicit find operation:

Inserting a new definition in a JSON schema with more than 100k lines

And this also works the other way around, whenever you add a $ref keyword to your JSON schema in the editor, the analyzer will tell you if the referenced definition can be successfully resolved.

“And do I get those nice validation error indicators which are saving so much time on editing my JSON content in the editor?” Yes, you do:

Active background validation on using a huge JSON schema

JSON editor in a nutshell: Using JSON pretty-print

Maybe, you often have to deal with JSON data which is not formatted as you like or has no white space at all. As an example, it is hard to edit this JSON text in the editor:

JSON data with no white-space is hard to read
JSON data with no white-space

What you need is an editor that a) understands the JSON syntax and b) can quickly format your JSON data hassle-free.

Format JSON data with no white space in the editor

In JSONBuddy, just use the pretty-print feature to format the current text content at any time. The keyboard shortcut for the pretty-print command is Ctrl+Shift+p (you can change the shortcut in the “Options…” dialog). There is also a menu item at “JSON | Pretty-print JSON”. After the formatting the JSON data is much more readable and can be easily modified in the editor:

JSON data after running the pretty-print command.

Note that short array content is aligned at a single line (available with JSONBuddy 5). This makes the JSON more compact and is saving space in the editor window. This is also true for arrays with only primitive types and having no long string values. As a consequence, arrays with many items of only primitive types, often numbers, are still displayed in a compact way with no new-lines separating the single items. In contrast, arrays with long string values are displayed with each item on a new line to increase readability. The editor applies an adaptive JSON formatting based on the actual content.

Use pretty-print in combination with the navigation history

The pretty-print functionality is getting even more powerful in combination with the navigation history of the JSON editor. If you format your JSON data while you are adding new properties, objects or arrays, the navigation history sets the text selection to the current property, after you applied the formatting operation.

You can also use the “Navigate Backward Ctrl+Shift+,” and “Navigate Forward Ctrl+Shift+.” commands to navigate through the selection history as you need.

Tales from support: JSON code folding

Someone who set “Recommend: yes” and “Overall quality: 1” (best) on the survey form sent the additional following feedback:

Code folding for JSON file does not work for situations like: “RaceCar”: { “Domestic”: true, “Model”: [] }

Unfortunately, the user did not provide an email address so I couldn’t get in contact with her/him. So what is the JSON editor doing with JSON data like this in terms of code folding? The sample data is all in one line. There is actually no chance for the editor to show code folding for JSON content that spans over a single line.

Use JSON pretty-print to show code folding

However, if you are using JSONBuddy as your JSON editor you also get a very useful pretty-print functionality that can be quickly executed by just pressing Ctrl-Shift-P. The sample JSON is immediately formatted in the following way:

Formatting JSON with pretty-print in JSONBuddy
Formatting JSON with pretty-print in JSONBuddy

As you can see, folding is available after the JSON data is formatted in the editor. It is also convenient that the current selection is also preserved after the pretty-print operation is completed. Maybe a small but important detail to provide the best JSON editor experience possible.

Instant validation while editing JSON data

Are you tired of clicking the “Validate” button or pressing F11 every time you want to know if your JSON data has still some validation errors? Then there is the good news. With JSONBuddy 4.5 you don’t need to run the JSON validator explicitly anymore while you are working on your JSON data in the editor. Instead, you always get all issues displayed as text indicators instantaneously and directly in the JSON editor. You also get the error message shown as call-tip if you hover with the mouse over the indicator for a short while:

JSON validator runs in the background in the editor
JSON validator runs in the background in the editor

Instant validation at any time

This allows a new way of working with JSON documents in JSONBuddy. You just open the JSON and if there is already a schema assigned, you can immediately see if the JSON data has errors or not. And to make it easier to fix any issues and to know what values are actually available for the enumeration, the editor will also display an entry-helper if you are going to fill the property:

Enum values from the assigned JSON schema
Enum values from the assigned JSON schema

So in summary, you always see any errors immediately and you get instant help if you want to fix them in the editor while you are editing your JSON data. Both make working with JSON more convenient and help to save time. Two important things to provide the best JSON editor experience possible.

Tales from support: Spaces for indentation

During the development of JSONBuddy 4.5 we got a customer inquiry about the need to use spaces instead of tabs for indentation levels in the JSON editor. So we added this setting to the “Editor” page of the “Options” dialog:

Option to use tab or space for indentation
Option to use tab or space for indentation

If you remove the check from the “Use tabs for indentation” check-box, the editor will insert spaces to set the indentation level for every new line. This setting is also used for JSON pretty-print and the various conversion operations of JSONBuddy.

Please keep in mind that this doesn’t replace any tabs which are already inserted. Any existing JSON data with either spaces or tabs as indentation will keep the characters currently used. In addition, the indentation functionality copies the white-space characters from any previous line. So don’t be confused if any new line has still tab characters inserted because the previous line uses tabs as indentation. Any new document in the JSON editor will use the setting from above right from the start.