runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Introduce System.Json as a Json.Net-compatible foundational library

Open vermorel opened this issue 10 years ago • 30 comments

JSON has entered the global software ecosystem with a force that is as strong, arguably stronger, than XML was in its time. In the .NET ecosystem, for years, it has been striking that the framework was not supporting JSON in a built-in way. As a result, Newtonsoft.Json is now the No1 package on Nugget.

I suggest that the foundational libraries should include a System.Json library with an API compatible with Newtonsoft.Json.

Indeed, as it stands Json.NET represents a tax that every .NET developer need to pay: you have to discover first why there is no built-in way to deal with JSON, then you have to discover that this one specific third party package is worthy to be trusted. I am not dismissing the quality of this excellent package, but this massive hit primarily demonstrates that JSON should be part of the foundational libraries of .NET.

Then, taking the longer view, I am worried - and I believe others should be - about the long term implications of having such a narrow yet mission-critical library developed and maintained separately. .NET Core can be a viable economic product to maintain over time even without the backing of Microsoft. However, Json.NET alone is not economically viable, not even through commercial support, not only 10 years time scale anyway.

The project might or might no go the way ServiceStack went (another great project by the way). Also, the commit profile of this project, with the first contributor having literally over 100x more commits than the second, a scenario ala NDoc is not to be ruled out either. Presently, Newtonsoft is taking the path of building complementary products on top of Json.NET, which again is very good, yet should not be relied upon for the future of .NET.

Opening .NET to the community is great. However, the fundational libraries should cover the very basic use cases. XML is covered, JSON should be as well. In particular, "outsourcing" narrow yet critical components is paving the way for upcoming messes ala left-pad.

Ideally, System.Json would be API-compatible with Newtonsoft.Json. There are multiple ways to achieve that. Starting a discussion on this precise matter between corefx representants and James Newton-King would be a start.

vermorel avatar Jun 05 '16 09:06 vermorel

JSON should be part of the foundational libraries of .NET.

Are you saying that the proposed System.Json should be part of NetStandard.Library? Wouldn't it be easier to just make Newtonsoft.Json part of it instead?

svick avatar Jun 05 '16 12:06 svick

Wouldn't it be easier to just make Newtonsoft.Json part of it instead?

Maybe. The package name feels inconsistent though. .NET developers - present and future - should not have to investigate packages one by one to be sure they can be trusted. Consistent naming is one of strong point of .NET compared to many alternative frameworks.

vermorel avatar Jun 05 '16 18:06 vermorel

@svick No, System.Json is actually way better basic and ease to use than NewtonSoft.Json

NewtonSoft.Json is good when you want to work with dynamic and arbitrary type serialization. But sometimes it just overkill and System.Json is plainly simple

Also I'm actually disappointed about the fact that NewtonSoft.Json.Linq does not even have JObject.Load(Stream stream). So, well, NewtonSoft.Json should drop it and use System.Json internally instead

Thaina avatar Dec 16 '16 14:12 Thaina

It's worth taking into account that while Newtonsoft's Json.NET is a very good library; It's fast, but it's not the fastest. As such, it is probably a matter of time before one of the 'make it go fast' guys in the Kestrel space identifies it as the bottleneck and wants to make it go faster. Kestrel is doing well in the plaintext benchmarks, but falls down a bit in comparison when it starts dealing with JSON.

With the amount of features that the library supports I don't think strapping Channels onto it and using Span<> everywhere is going to be a straight forward change. So I wouldn't be surprised if it's deemed less work to create yet another library (System.IO.Pipelines.Json ?). Though I very much doubt it would be as feature rich as Json.NET.

BoltR avatar Dec 16 '16 18:12 BoltR

@vermorel, You make excellent points, and I agree with them completely. I have been using Newtonsoft.Json and have been almost since the time it was first released. With every new update of the .NET framework, I always expect that Microsoft will have included some equivalent of Newtonsoft.Json. To my repeated surprise, they never do. As you have mentioned Newtonsoft.Json 1) fills a major gap in .Net performance, and 2) is, by far, the most popular NuGet package.

The Internet sits at the center of the entire computing industry. JSON has become the defacto method of transferring data payloads across that Internet. Therefore, a high-performance JSON library should be a key component of any Web development framework.

It doesn't matter to me so much whether Microsoft includes Newtonsoft.Json generally intact (but with updated namespaces) or if they roll their own equivalent. What matters is that they fix the deficiency that exists now.

agatlin avatar May 20 '17 15:05 agatlin

Therefore, a high-performance JSON library should be a key component of any Web development framework.

It is. Newtonsoft.Json serves as that library in ASP.NET Core.

What matters is that they fix the deficiency that exists now.

I'm unclear what exactly the deficiency is, according to you.

Namespace itself doesn't mean anything, I can publish a package like System.Nonsense (or Microsoft.Nonsense), but it doesn't mean it contains high-quality code approved by Microsoft.

Also consider all the issues that occur when there are two competing ways to do the same thing (confusion, bad interoperability, breaking existing code, etc.). What are the advantages that outweigh these significant disadvantages?

svick avatar May 20 '17 17:05 svick

it contains high-quality code approved by Microsoft.

I wish something as common as JSON should have a library with high-quality code approved by Microsoft. Like System.XML

Introducing System.Json (back) into corefx would not breaking anything of anyone already using Newtonsoft.Json because it has difference namespace so I don't know why two competing ways to do the same thing can leads to bad interoperability and breaking existing code. Even confusion is not likely to be

Also as many was mentioned. Newtonsoft.Json is great library. But is not high-performance JSON library compared to the original System.Json

As I said. NewtonSoft.Json is good when we want to work with dynamic or arbitrary type serialization. But sometimes it just overkill and System.Json is plainly simple

System.Json is actually way better basic and ease to use than NewtonSoft.Json when we want to just manipulate JsonObject as a dictionary

Thaina avatar May 20 '17 17:05 Thaina

Also what System.Json actually contains can only be compared to just NewtonSoft.Json.Linq

But the thing is. NewtonSoft.Json should be extended to System.Json and System.Json itself should be the reliable library anywhere because JSON is so common nowaday. It too common to the point that it should not need nuget. If we don't need nuget for System.Text.Encoding or System.Net or System.Xml then System.Json should also be there

Thaina avatar May 20 '17 17:05 Thaina

@Thaina

I wish something as common as JSON should have a library with high-quality code approved by Microsoft. Like System.XML

Newtonsoft.Json is like that too. If the code wasn't high-quality and approved by MS, they wouldn't use it in their products, like ASP.NET Core.

Newtonsoft.Json is great library. But is not high-performance JSON library compared to the original System.Json.

You seem to want something different than other people here. They keep saying what they want is basically renamed Newtonsoft.Json.

Also, according to this benchmark, Newtonsoft.Json is significantly faster than System.Json.

I don't know why two competing ways to do the same thing can lead to bad interoperability […]

If one piece of code uses Newtonsoft.Json and another uses System.Json and I need to use both of them, I will have issues. That's why having one library that almost everyone uses is better.

I don't know why two competing ways to do the same thing can lead to […] breaking existing code

Some Microsoft libraries and frameworks already use Newtonsoft.Json. Are you saying System.Json should be added, but all those libraries should keep using Newtonsoft.Json? Yes, that wouldn't break existing code, but it would make System.Json much less appealing.

It too common to the point that it should not need nuget.

It needs NuGet exactly as much as ASP.NET Core does (e.g. on .Net Core 2.0, Newtonsoft.Json is included in the package store, along with ASP.NET Core and other 3rd party libraries like libuv, Serilog or Remotion.Linq).

svick avatar May 20 '17 18:05 svick

Some Microsoft libraries and frameworks already use Newtonsoft.Json. Are you saying System.Json should be added, but all those libraries should keep using Newtonsoft.Json? Yes, that wouldn't break existing code, but it would make System.Json much less appealing.

I don't see that would be breaking anything exist. Well, because I just want the original System.Json not renaming the NewtonSoft.Json. System.Json object class even have different name than NewtonSoft.Json

And I'm also against renaming NewtonSoft.Json. Even if it included it in corefx I would like it still having the creator name as namespace

It needs NuGet exactly as much as ASP.NET Core

ASP.NET core does not the only place we use C#. I use C# in unity (well, as well as dotnet core) and there can't use nuget. Many places does not adopt nuget system. So, again, I think something as common as System.Json should always exist as standard

And even NewtonSoft.Json would be faster. Common functionality should still exist. And the thing that make NewtonSoft.Json faster is about serialize and deserialize a class. That should be able to extended from System.Json or maybe not related to System.Json at all. Because the original System.Json has different functionality compare to NewtonSoft.Json

As I said, original System.Json could only be compared NewtonSoft.Json.Linq

Newtonsoft.Json is significantly faster than System.Json

I remembered that in that BenchMark they only profiling the serialization to class. Which I know NewtonSoft.Json is really great for that work. But what I mean is, the most simple way we use Json is as JsonObject and JsonArray without serialize or deserialize, just parsing and manipulate. System.Json is better and simpler

NewtonSoft.Json has the same kind of functionality as NewtonSoft.Json.Linq and that cannot use in unity. I can bring System.Json to use in unity because it lighter in almost all aspect

Thaina avatar May 21 '17 02:05 Thaina

As others have mentioned, JSON is one of the popular data formats, used more often than XML. Most of languages have native support of JSON. It only makes sense to include the support of it in Core.

Li-ReDBox avatar Aug 21 '17 05:08 Li-ReDBox

Json in std lib is a great idea. Adopting Json.net however, not so great. It has too much baggage from it's early decisions.

oliverjanik avatar Sep 11 '17 05:09 oliverjanik

Please add this into the core libraries.

Squirrelies avatar Nov 20 '17 03:11 Squirrelies

JSON.NET is way too big to be included in small helper tools. My app is 20k and JSON support adds 600+k to that. See the issue? I understand that .NET adds a lot more, but it's part of Windows so it's just there, like System.Xml. Right now I can have XML config files without any additional space costs. JSON config files are overly expensive to support.

I'm going to have to try out those hard-to-discover simpler JSON libraries for C#.

ygoe avatar Feb 01 '18 14:02 ygoe

Newtonsoft.Json is way too broken to be added, period. We need a new light and swift implementation.

oliverjanik avatar Feb 01 '18 23:02 oliverjanik

System.Json was made available for .NET Core does that satisfy the original request here?

danmoseley avatar Feb 01 '18 23:02 danmoseley

I have been using System.Json and find it is OK. The problem is, as @ygoe mentioned, if you want to use JSON config in you application, then JSON.NET is one dependency which is not good for certain applications. Of course, you can use XML but ...

Li-ReDBox avatar Feb 02 '18 00:02 Li-ReDBox

@danmosemsft I am very appreciate that System.Json was available in nuget but still it should just included in corefx to be standard like System.Xml

Thaina avatar Feb 02 '18 00:02 Thaina

OK, I'm going to close this as resolved then.

System.Json hasn't received much investment in years - I think it was a Silverlight library originally. We would take changes to improve it, as long as it remained compatible.

danmoseley avatar Feb 02 '18 00:02 danmoseley

I am very appreciate that System.Json was available in nuget but still it should just included in corefx to be standard like System.Xml

@Thaina the boundary of the core package is really chosen as a convenient package of the most commonly used types. It balances size vs usage. If a library is not included, it does not necessarily mean that it isn't fully supported.

danmoseley avatar Feb 02 '18 00:02 danmoseley