GitHub

System.Text.Json

Join the chat at https://gitter.im/ysharplanguage/FastJsonParser

"Small is beautiful."

This is a minimalistic and fast JSON parser / deserializer, for full .NET.

The complete source code of the parser is pretty short (in a single source file less than 1,700 SLOC-long, not counting the comments) and comes with some speed tests and their sample data, all in the "JsonTest" and "TestData" folders.

The console test program includes a few unit tests (for both nominal cases vs. error cases), and it will attempt to execute them before the speed tests - see ParserTests.cs.

Do not hesitate to add more of the former (i.e., unit tests) and/or to raise here whatever issues you may find.

There's a link to this repository at json.org (in the C# implementations section).

Design goal

This aims at parsing textual JSON data, and to deserialize it into our (strongly typed) POCOs, as fast as possible.

For now, the main tiers of interest for this parser are the desktop / server tiers. There are other JSON librairies with good performance, and already well tested / documented, which also support mobile / handheld devices that run more limited flavors of .NET (e.g., Json.NET and ServiceStack come to mind).

However, Sami was able to do a quick performance test on his Android device (as the code could luckily compile for it as-is), and came up with a few benchmark results (a dozen or so) which do seem encouraging - i.e., see this thread of Xamarin's Android forum :

http://forums.xamarin.com/discussion/comment/39011/#Comment_39011

Thus, starting with version 2.0.0.6, Android and WP8 are also supported (see NuGet section below).

Thank you Sami :)

Available on NuGet

For convenience :

Desktop version

Mobile versions for Android and WP8

Development status

Although it is promisingly fast, lightweight, and easy to use, please note this parser / deserializer is still mostly experimental.

For one simple thing to begin with, it is in need of more comprehensive JSON conformance tests.

That said, just feel free to fork / bugfix / augment / improve it at your own will.

Of course, I welcome your informed input and feedback.

Please read and accept the terms of the LICENSE, or else, do not use this library as-is.

Public interface

Consists mainly in these six (three generic ones, and three non-generic ones) instance methods :

T Parse<T>(string input)

and

T Parse<T>(System.IO.TextReader input)

and

T Parse<T>(System.IO.Stream input)

and

object Parse(string input)

and

object Parse(System.IO.TextReader input)

and

object Parse(System.IO.Stream input)

The capability to parse JSON text coming thru a stream (reader) is clearly a must-have, past a certain size of payload - "have mercy on your CLR large object heap".

Note that if you don't care (i.e., don't need / don't want to bother) deserializing whatever input JSON into POCOs, you can then just call these methods with

object

for the generic type argument, as in, e.g. :

"parser.Parse

Read the original on github.com ↗