Introduction
JSON (JavaScript Object Notation) is an open standard format to transfer data between server and client applications. Its kind of an alternative to XML format and used mostly in current development. Due to more usage of JSON in projects, Microsoft has added "JSON Visualizer" to Visual Studio debugger With Visual Studio 2013 Update 2.
This post shows what are the features of JSON Visualizer with sample C# example.
Sample JSON:
{
"array": [
1,
2,
3
],
"boolean": true,
"null": null,
"number": 456,
"object": {
"a": "b",
"c": "d",
"e": "f"
},
"string": "Hello World"
}
C# Example:
We have copied above sample JSON data to string variable "sampleJSON" and try to see features of JSON Visualizer.
namespace DotNetMirror
{
class JSONVisualizerDemo
{
public static void Main()
{
string sampleJSON = "{\"array\":[1,2,3],\"boolean\":true,\"null\":null,\"number\":123,\"object\":{\"a\":\"b\",\"c\":\"d\",\"e\":\"f\"},\"string\":\"Hello World\"}";
}
}
}
Where to see JSON Visualizer:
JSON Visualizer comes in debugging mode of your application. Click the search icon that appears next to a variable name in DataTips/Watch/Autos/Locals/Quick Watch window. You can find list of visualizers, out of which you can choose JSON Visualizer.
Fig#1 : Getting JSON Visualizer from DataTips
Fig#2 : Getting JSON Visualizer from Autos
Fig#3 : Getting JSON Visualizer from Immediate Window
Now we know how to invoke JSON Visualizer and below we will see features of it.
Feature#1 : Shows JSON encoded strings in a TreeView format
We can see the JSON objects data as TreeView format. It will be simpler and useful if we have large JSON data.
Fig#4 : JSON Data Objects in TreeView format
Feature#2 :Search and Highlight string
If we have large amount of JSON data, with search feature it automatically hightlight the matched occurances.
Fig#5 : JSON Visualizer with Search and Highlight
Feature#3 : copy path, key value and Item
You can right click on particular object and copy path/key/value/Item.
Fig#6 : JSON Visualizer Copy Data
Feature#4 : Validates JSON - String is not JSON Formatted
If we have any invalid string in JSON data then JSON Visualizer shows as "String is not JSON Formatted" error. In the below image you can see we have added test keyword before brace.
Fig#7 : JSON Visualizer with validation check
Note: JSON visualizer works for all languages and project types currently supported by Visual Studio debugger (C#.NET, VB.NET, C++, JavaScript, etc.)