JSON literal expressions
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
Despite being out of vogue, XML is still in use in tons of businesses and many VB customers I talk to continue to enjoy the feature. It's natural to ask whether we can duplicate the wins here with JSON. I was a little hesitant on JSON until I saw that SQL Server 2016 has built-in JSON support.

I've implemented a working prototype [here](https://github.com/AnthonyDGreen/roslyn/tree/features/vb-json) though it's out of date and needs updating to work with the latest Roslyn sources/VS2017. It's build around JSON.NET. The syntax is just JSON:
``` VB.NET
Dim obj As JObject = { "messageType": "", "content": "SomeText" }
```
And like XML it supports embedded expressions:
Any value not native to JSON (string, number, JSON object, JSON array, true, false, null) is an embedded expression:
``` VB.NET
Dim obj As JObject = { "name": }
```
Any key not a string is an embedded expression.
``` VB.NET
Dim obj As JObject = { : "" }
```
Any member not a key-value-pair is an embedded expression.
``` VB.NET
Dim obj As JObject =
{
"key1": "value1",
from kvp in dictionary select (e.key: e.value)
}
```
The big "win" uses I imagine are copying and pasting a JSON example/message from some website into your code and then substituting in your own dynamic values with embedded expressions. I hope this could be a powerful tool for communicating to REST services since users won't have to create separate POCO objects and serialize them or manually construct JSON.NET JObjects:
The second big win use is pairing JSON literals with pattern matching, enabling the developer to decompose a JObject off the wire without deserializing to a .NET Object.
``` VB.NET
Select Case message
Case Match { "messageType": "ack",
"timestamp": Date(d) }
Console.WriteLine($"Message receipt received at {d}")
End Select
```
No need for any special member access syntax since the ! operator works natively with JSON.NET objects. We should consider some sort of pattern-based support so the feature could target either JSON.NET or Windows.Data.Json but if we can only do one, JSON.NET is preferred.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.