Json5 1.0.4

dotnet add package Json5 --version 1.0.4
                    
NuGet\Install-Package Json5 -Version 1.0.4
                    
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.
<PackageReference Include="Json5" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Json5" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Json5" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Json5 --version 1.0.4
                    
#r "nuget: Json5, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Json5@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Json5&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Json5&version=1.0.4
                    
Install as a Cake Tool

EULA OSS GitHub

A JSON5 parser for .NET built entirely on top of the public System.Text.Json API surface. Requires .NET 10+.

Usage

Parse to JsonNode

using Json5;

JsonNode? node = Json5.Parse("""
    {
        // comments are allowed
        unquoted: 'single-quoted string',
        hex: 0xDECAF,
        leadingDot: .5,
        trailing: 'comma',
    }
    """);

Deserialize to a typed object

var config = Json5.Deserialize<AppConfig>(json5String);

Parse to JsonDocument

using var doc = Json5.ParseDocument(json5String);
JsonElement root = doc.RootElement;

Convert to standard JSON

string json = Json5.ToJson(json5String);
byte[] utf8 = Json5.ToUtf8Json(json5Bytes);

Write to Utf8JsonWriter

Json5.WriteTo(json5String, writer);

JSON5 Features

All JSON5 extensions beyond standard JSON are supported:

Feature Example
Unquoted object keys { foo: 1 }
Single-quoted strings 'hello'
Multi-line strings (escaped newlines) 'line1\↵line2'
Hexadecimal numbers 0xFF
Leading/trailing decimal points .5, 2.
Explicit positive sign +1
Infinity, -Infinity, NaN Infinity
Single and multi-line comments // … and /* … */
Trailing commas [1, 2,]
Additional escape sequences \v, \0, \xHH
Extended whitespace Unicode Zs category, BOM

Auto-Dedent Multi-line Strings

When parsing multi-line string values, you can automatically remove common leading whitespace via Json5ReaderOptions.AutoDedent. This makes it easier to write readable indented code without the indentation appearing in the final string value.

var options = new Json5ReaderOptions { AutoDedent = true };
var node = Json5.Parse("""
    {
        description: '
            This is a multi-line string
            with consistent indentation
            that will be removed.
        '
    }
    """, options);
// description will be: "This is a multi-line string\nwith consistent indentation\nthat will be removed."

The algorithm:

  1. Strips the first line if blank
  2. Strips the last line if blank
  3. Finds the minimum common leading whitespace across all remaining non-blank lines
  4. Removes that minimum indent from every line

Only string values are affected; property names are never dedented. Blank lines within the string are preserved.

Infinity / NaN Handling

Since standard JSON has no representation for Infinity and NaN, the behavior is configurable via Json5ReaderOptions.SpecialNumbers:

Mode Behavior
AsString (default) Emits as "Infinity", "-Infinity", or "NaN"
AsNull Emits as null
Throw Throws Json5Exception
var options = new Json5ReaderOptions 
{ 
    SpecialNumbers = SpecialNumberHandling.AsNull 
};
var node = Json5.Parse("Infinity", options); // returns null

Open Source Maintenance Fee

To ensure the long-term sustainability of this project, users of this package who generate revenue must pay an Open Source Maintenance Fee. While the source code is freely available under the terms of the License, this package and other aspects of the project require adherence to the Maintenance Fee.

To pay the Maintenance Fee, become a Sponsor at the proper OSMF tier. A single fee covers all of Devlooped packages.

Sponsors

Clarius Org MFB Technologies, Inc. Khamza Davletov SandRock DRIVE.NET, Inc. Keith Pickford Thomas Bolon Kori Francis Reuben Swartz Jacob Foshee alternate text is missing from this package README image Eric Johnson Jonathan Ken Bonny Simon Cropp agileworks-eu Zheyu Shen Vezel ChilliCream 4OTC domischell Adrian Alonso torutek mccaffers Seika Logiciel Andrew Grant Lars prime167

Sponsor this project

Learn more about GitHub Sponsors

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Json5:

Package Downloads
Json5.Configuration

A Microsoft.Extensions.Configuration provider for JSON5 files, on top of the Json5 parser.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 254 4/13/2026
1.0.3 57 4/13/2026
1.0.2 64 4/8/2026
1.0.1 54 4/8/2026