JSON Libraries
Simple and fast in-memory JSON manipulation
Highlights
Lightweight
Small library, small memory footprint, just a few really needed types.
Fast
Faster than the most popular JSON library in all aspects.
Simple
Compact and self intuitive syntax.
What is KGySoft.Json
First of all, what it is not: It’s not a serializer (though see the Examples section of the JsonValue
type). It is rather a simple Domain Object Model (DOM) for JSON (or LINQ to JSON if you like), which makes possible to manipulate JSON content in memory in an object-oriented way (similarly to XDocument
and its friends for XML).
What’s wrong with JSON.NET?
Nothing. It knows everything (and more). It was just too heavy-weight for my needs and I didn’t like that a lot of libraries reference different versions of it, causing version conflicts. Note though that it’s not the fault of JSON.NET; it’s just the consequence of popularity (the same could be true even for this library if it was so popular… but I don’t really think it could be a real issue anytime soon).
What’s wrong with System.Text.Json?
Well, it’s a bit different thing. As an in-memory JSON tool, it is read-only (JsonDocument
/JsonElement
) so you cannot build in-memory JSON content with it. It was introduced with .NET Core 3.0, so below that you have to use NuGet packages, which may lead to the same issue as above (but even with NuGet, it’s not supported below .NET Framework 4.6.1). Apart from those issues, it’s really fast, and mostly allocation free (well, as long as your source is already in UTF8 and you don’t access string elements).
.NET 6 Update: Starting with .NET 6, a new
System.Text.Json.Nodes
namespace has been introduced that supports JSON DOM manipulation as well, and uses a very similar approach to this library. Even the member names are very similar. There are some important differences, though: the System version does not tolerate getting lost in the domain, eg.json["someProperty"][42]["WhereAmI"]
will throw exceptions instead of returningundefined
. Similarly, the SystemAsObject
/AsArray
members may throw exceptions, whereas in the KGy SOFT version these return nullable results. If you can target at least .NET 6, then the choice can be a matter of taste.
Download
In Visual Studio
The preferred way is by the NuGet Package Manager in Visual Studio
- You can use either the Package Manager Console:
PM> Install-Package KGySoft.Json
- Or the Package Manger GUI by the Manage NuGet Packages… context menu item of the project.
Direct Download
Source Code
The source is available on GitHub.
Examples
Tip: See also the examples at the Remarks section of the
JsonValue
type.
Simple Syntax
The JsonValue
type is the base building block of JSON content, which can be considered as a representation of a JavaScript variable (see also the JsonValueType
enumeration). It also behaves somewhat similarly to JavaScript:
Writing JSON
Parsing JSON
Manipulating JSON
Help
Browse the online documentation for examples and detailed descriptions.
License
This repository is under the KGy SOFT License 1.0, which is a permissive GPL-like license. It allows you to copy and redistribute the material in any medium or format for any purpose, even commercially. The only thing is not allowed is to distribute a modified material as yours: though you are free to change and re-use anything, do that by giving appropriate credit. See the LICENSE file for details.