Suppose you had a program with the following code:

var json =
"""
    "name":"james bond",
    "retired":true,
    "age":45
""";

Console.WriteLine(json);

It looks like this on Visual Studio

vsNormal

And like this on Visual Studio Code

vsCodeNormal

And like this on Rider

riderNormal

Very straightforward.

Did you know it is possible to tell your IDE that the string is json?

Do that by adding the following comment just before the string

//lang=sql
var json =
"""
    "name":"james bond",
    "retired":true,
    "age":45
""";

It will look like this in Visual Studio, with a squiggly indicator. Notice also the syntax highlighting

vsHint

If you hover your mouse over that you see the following:

vsHintTooltip

It is basically saying that the json is invalid (no opening and closing curly braces!)

The same thing for Visual Studio Code

vsCodeHint

And if you hover your mouse …

vsCodeHintTooltip

This also works with Rider

riderHint

If you mouse over …

riderHintTooltip

This also works for a few other domain specific languages:

  1. Regular Expressions
  2. SQL
  3. XML
  4. Javascript
  5. CSS
  6. HTML

Happy hacking!