The Customer Tech Preview (CTP2) release of Visual Studio 2013 Update 2 contains a new JSON editor. In this release, the JSON editor includes a number of features such as colorization, and JSON syntax validation. More features will be added during subsequent releases.
New JSON item template
In a web application, you can use the new JSON item template under the Markup category to add a new file with the .json extension.
When opening a file in the JSON editor, the content will be tokenized and have distinct colors. Invalid tokens will have the default black color as shown below.
The color for numbers can be set using the setting at Tools –> Options –> Environment –> Fonts and Colors –> Number.
JSON syntax validation
Visual Studio 12 Update 2 will validate JSON syntax and provide squiggle syntax errors that have been detected, and list them in the Error List window. Double-clicking on an error in the Error List will bring the file to the foreground if it’s not currently active and put the cursor at the error.
Automatic brace completion and type-through
When you type an opening bracket or quote, the matching closing character is automatically inserted after the cursor. If you type the automatically inserted character, you will “type through” that character. This would help keep your fingers in home position and maintain the typing flow.
Outlining is available for the JSON content so you can choose to either collapse or expand any part of the content for easy viewing.
Tools Options Settings
In addition to the general Text Editor settings, we offer the Validation settings under the Advanced tab that you can change to suite your desire.
JSON content sniffing
When double-clicking a file in Solution Explorer to open a file with an unknown extension, the JSON editor will scan through the content of the file and determine if it’s indeed a JSON file. If so, the JSON editor will open the file and you will see all of the features mentioned above.
However, if the JSON editor detects that there are more than 5 errors in the first 4 kilobytes of the content, it will quit and the file will be treated the same way as an unknown file extension, where it will be opened in whatever editor set as the default.
There will be additional features in the JSON editor in subsequent releases and we will blog more about them when they become available.