New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON serialization/deserialization APIs #160

Closed
SteveSandersonMS opened this Issue Feb 23, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@SteveSandersonMS
Member

SteveSandersonMS commented Feb 23, 2018

We need JSON handling for even the simplest apps (including our project template), so we have to have something for 0.0.5.

We'll probably bundle a minimal JSON serializer/parser inside Microsoft.AspNetCore.Blazor, and recommend that if people require anything more sophisticated they use a third-party package. The IL stripping will remove our built-in implementation on publish if it isn't actually getting called, so there's no runtime cost.

@SteveSandersonMS SteveSandersonMS added this to the 0.0.5 milestone Feb 23, 2018

@SteveSandersonMS SteveSandersonMS referenced this issue Feb 23, 2018

Closed

HttpClient #19

0 of 1 task complete
@Terricide

This comment has been minimized.

Terricide commented Feb 23, 2018

This is a single file json library that I've used in my projects that works well.

https://github.com/facebook-csharp-sdk/simple-json

@SteveSandersonMS

This comment has been minimized.

Member

SteveSandersonMS commented Feb 23, 2018

@Terricide Interesting - thanks! We already have MiniJSON (see this and this) in the project which is quite a lot smaller and simpler. I'm not sure about the pros/cons versus simple-json. Do you know how they compare?

@Terricide

This comment has been minimized.

Terricide commented Feb 23, 2018

No sorry I've never used minijson. I've just used simplejson with a few fixes of my own for about 4 years now and it has been working well.

I've actually been using it in an app that is targeting .net 2.0 (not .net core 2.0)

@SteveSandersonMS

This comment has been minimized.

Member

SteveSandersonMS commented Feb 26, 2018

OK, this is now in. Following @Terricide's recommendation, it does use SimpleJson internally (though it's marked internal, so we can always change the implementation later).

I tried the following:

  • MiniJSON: Very small (~3kb). Only has native support for deserializing to Dictionary<string, object>. We can add support for deserializing to arbitrary types (and we did so before) but that code hasn't been widely battle-tested. Underlying library is not in active development.
  • SimpleJson: Quite small (~9kb). Natively supports serializing/deserializing arbitrary types. Natively supports disabling Reflection.Emit usage, which should make it faster (Reflection.Emit creates slow code on non-JIT platforms). Does not appear to be in active development.
  • LitJSON: Moderately small (~17kb). Natively supports serializing/deserializing arbitrary types. Is definitely still under active development. Unfortunately made some tests fail due to correctness issues like LitJSON/litjson#43, hence not considering it any further.
  • Json.NET: Very large (~200kb). Natively supports everything and is under active development, but just too big to take as a built-in dependency.

The sizes quoted refer to how much bigger it makes the app payload after gzip compression.

I did not do any perf benchmarking. If anybody is interested enough to compare the relative speeds of these libraries when running on WebAssembly, please let us know what you find!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment