QuickJson 1.0.0
See the version list below for details.
dotnet add package QuickJson --version 1.0.0
NuGet\Install-Package QuickJson -Version 1.0.0
<PackageReference Include="QuickJson" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
paket add QuickJson --version 1.0.0
#r "nuget: QuickJson, 1.0.0"
// Install QuickJson as a Cake Addin
#addin nuget:?package=QuickJson&version=1.0.0
// Install QuickJson as a Cake Tool
#tool nuget:?package=QuickJson&version=1.0.0
QuickJson
✅ Project status: active.
QuickJson is a very basic JSON parser distributed as a source-only NuGet package, which allows it to be referenced without imposing any runtime dependencies.
Download
📦 NuGet: dotnet add package QuickJson
Usage
⚠ To use this package, your project needs to target C# 8 or later. You can ensure this by setting
<LangVersion>latest</LangVersion>
in the project file.
To parse a JSON string, call Json.TryParse(...)
or Json.Parse(...)
:
// This returns null on invalid JSON
var json = Json.TryParse("{ \"foo\": [ 69, true, \"bar\" ] }");
// This throws on invalid JSON
var json = Json.Parse("{ \"foo\": [ 69, true, \"bar\" ] }");
To retrieve a nested node in the parsed JSON, use TryGetChild(...)
:
// May return null if the property doesn't exist
// or if the referenced node is not an object
var foo = json.TryGetChild("foo");
// May return null if the child doesn't exist
// or if the referenced node is not an array
var child1 = foo?.TryGetChild(0);
var child2 = foo?.TryGetChild(1);
var child3 = foo?.TryGetChild(2);
Alternatively, you can also enumerate all object properties using EnumerateProperties()
or all array children using EnumerateChildren()
:
// Returns an empty enumerator if the referenced node is not an object
foreach (var prop in json.EnumerateProperties())
{
var name = prop.Name; // string
var value = prop.Value; // JsonNode
// ...
}
// Returns an empty enumerator if the referenced node is not an array
foreach (var child in json.EnumerateChildren())
{
// ...
}
In order to extract values from nodes, use TryGetNumber()
, TryGetBool()
, or TryGetString()
:
// May return null if the node contains a value of a different kind
var value1 = child1?.TryGetNumber(); // 69
var value2 = child2?.TryGetBool(); // true
var value3 = child3?.TryGetString(); // "bar"
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 3.5
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 2.0
- No dependencies.
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on QuickJson:
Repository | Stars |
---|---|
Tyrrrz/DotnetRuntimeBootstrapper
Bootstrapped framework-dependent deployment for .NET applications
|
Version | Downloads | Last updated |
---|---|---|
1.1.1-test | 153 | 7/26/2023 |
1.1.0 | 317 | 4/27/2023 |
1.0.0 | 670 | 6/26/2021 |