quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Support better C# json libraries

Open gotenxds opened this issue 1 year ago • 1 comments

Currently, quicktype is using newtonsoft json, one of the slowest json libraries for C#, which is a shame.

I suggest moving (or adding an alternative) to either Utf8Json or Spanjson which outperforms newtonsoft by a lot. See detailed comparison here

gotenxds avatar Jul 29 '22 21:07 gotenxds

System.Text.Json would be ideal. It's built-in to net 6.0+ and is high performance without compromising on features, support, or stability. That said, the primary concern with Newtonsoft is not its speed, which is sufficient for nearly all use cases, but the supportability mess with all the old versions floating around as dependencies. If you've ever worked on a project that needed a dependency on some old version of Newtonsoft.Json, you know what I'm talking about.

This project could easily leverage source generation in STJ, which boosts performance another 40% (not measured in that comparison link).

However, serialization is truly a separate concert from code generation, and should properly be factored out to a provider interface so you can bring whatever transport serializer you need.

prosser avatar Aug 16 '22 23:08 prosser

This has been asked before in #1347. Since I wanted Support for System.Text.Json to I typed some code that should add this. my fork https://github.com/bzuidgeest/quicktype/tree/SystemTextJson and the PR https://github.com/quicktype/quicktype/pull/1997

If I understand everything correctly it seems to pass a lot of the same tests that the newtonsoft stuff does. Basically there is an extra option framework that lets you choose between both options.

Its based on another fork its code with a number of fixes and made framework selectable.

Maybe you want to test.

Do note its nothing special. It basically emulates the style of the newtonsoft implementation. That's good enough for me.

bzuidgeest avatar Oct 02 '22 20:10 bzuidgeest

Fixed in #1997

dvdsgl avatar Jan 04 '23 06:01 dvdsgl