QuickJson 1.0.0

NuGet\Install-Package QuickJson -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package QuickJson --version 1.0.0
<PackageReference Include="QuickJson" Version="1.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add QuickJson --version 1.0.0
#r "nuget: QuickJson, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Build Coverage Version Downloads Donate

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"
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETFramework 3.5

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 1.0

  • .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.0.0 418 6/26/2021