New JSON parser in vNext : No Comments (Yet!)

Few days ago .Net team has announced about new JSON parser in Microsoft.Framework.Runtime which removed the dependancy on Newtonsoft.Json

Why did they removed dependency on Newtonsoft.Json?
Because Using Newtonsoft.Json in the run time prevents customers from choosing a specific version of Newtonsoft.Json in their applications. This change will allow customers to use any version of Newtonsoft.Json in their applications.

Ok, what it will parse basically?
Currently It is used to parse only the project.json, project.lock.json and global.json files.
Other components still use Newtonsoft.Json to parse JSON files i.e. Microsoft.Framework.PackageManager

Got it, That’s it or any other changes?
Umm… well one more thing, which is :

The new JSON parser doesn’t support the following syntax:
1. Comments in the form of // … and /* … */
2. Trailing commas after the last member of objects and arrays

Yes, I can feel your reaction, same as it was faced by .Net team when they announced this.

What was the main negative reaction?
It was for comments like why it is not supported.

Can you explain more like how will comments not supported?
Suppose you have very basic web project in vNext and you have project.json file as below:

 {
   "dependencies": {
     "Kestrel": "1.0.0-*",
     "Microsoft.AspNet.WebSockets.Server": "1.0.0-*",
     "Nowin.vNext": "1.0.0-*"
     },
   "commands": {
      "web": "Microsoft.AspNet.Hosting --server Nowin.vNext", 
       ////Here commenting like this will not be supported.
       "web-kestrel": "Microsoft.AspNet.Hosting --server Kestrel"
    }
}

Wait, does it mean that suppose for config files we will not be allowed to add comments?
For that there was nice answer from Mr David Fowler from Microsoft:

  • We’re using JSON, not any of those formats for the core project file. It’s JSON. Configuration we don’t care about as much, that can be in whatever format you choose, and that’s why there’s a provider model.
  • Build systems and project systems don’t let users choose what the file format is. Don’t mix up configuration files with project files. They are different beasts.
  • project.json, project.lock.json and global.json are not configuration files, they are part of the new project system.

Is there any work around for supporting comments?
There might be one solution like changing whole file format from JSON to any other like YAML, JSON5, TOML etc.

One more solution suggested by .Net team was :

What if we read both formats?

  1. If you have a project.json5 we’ll use that and you can add all the comments in the world.
  2. If you have a project.json, it’s strict JSON no comments allowed.

I’m not saying we’ll do this BTW but I want to see what people think (same for global.json but not project.lock.json, you don’t edit that one).

Something in deep? It might be look like: (Which is yet not confirmed)

image
Conclusion?

Conclusion of this situation is like for time being .Net team decided to stick with the industry standard JSON format.

Reasons for choosing JSON:

  1. Well, it’s an industry standard. That’s pretty neat.
  2. It has support in nearly every tool, web site, editor, parser, which leads to great interoperability.
  3. It is an easy-to-understand, human-readable/writable, computer-readable/writable format.
  4. It supports the right set of data structures: arrays, dictionaries, strings, numbers, Booleans.

And Mr Eilon Lipton from Microsoft said:

Though we’re not opposed to changing this(comments) in the future, this is where we are right now.

So, For now JSON format is fixed which would be parsed by new JSON parser and which will not allow comments in it.

I will update once updated from .Net team.

Till then keep faith in .Net team because they would definitely choose something awesome for all .Net users!

Advertisements

One thought on “New JSON parser in vNext : No Comments (Yet!)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s