Philiprehberger.FlattenJson 0.1.10

dotnet add package Philiprehberger.FlattenJson --version 0.1.10
                    
NuGet\Install-Package Philiprehberger.FlattenJson -Version 0.1.10
                    
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="Philiprehberger.FlattenJson" Version="0.1.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Philiprehberger.FlattenJson" Version="0.1.10" />
                    
Directory.Packages.props
<PackageReference Include="Philiprehberger.FlattenJson" />
                    
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 Philiprehberger.FlattenJson --version 0.1.10
                    
#r "nuget: Philiprehberger.FlattenJson, 0.1.10"
                    
#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 Philiprehberger.FlattenJson@0.1.10
                    
#: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=Philiprehberger.FlattenJson&version=0.1.10
                    
Install as a Cake Addin
#tool nuget:?package=Philiprehberger.FlattenJson&version=0.1.10
                    
Install as a Cake Tool

Philiprehberger.FlattenJson

CI NuGet Last updated

Flatten nested JSON objects into dot-notation key-value pairs, and unflatten them back.

Installation

dotnet add package Philiprehberger.FlattenJson

Usage

using Philiprehberger.FlattenJson;

// Flatten nested JSON
var flat = JsonFlattener.Flatten("""{"a":{"b":1,"c":[2,3]}}""");
// flat["a.b"] == "1"
// flat["a.c.0"] == "2"
// flat["a.c.1"] == "3"

// Null values are preserved
var flat2 = JsonFlattener.Flatten("""{"x":null,"y":{"z":42}}""");
// flat2["x"] == null
// flat2["y.z"] == "42"

// Custom separator
var flat3 = JsonFlattener.Flatten("""{"a":{"b":1}}""", separator: "/");
// flat3["a/b"] == "1"

// Unflatten back to JSON
var json = JsonFlattener.Unflatten(flat);
// => {"a":{"b":"1","c":["2","3"]}}

Arrays

using Philiprehberger.FlattenJson;

var json = """{"users": [{"name": "Alice"}, {"name": "Bob"}]}""";
var flat = JsonFlattener.Flatten(json);
// { "users.0.name": "Alice", "users.1.name": "Bob" }

Custom Separator

using Philiprehberger.FlattenJson;

var json = """{"db": {"host": "localhost", "port": "5432"}}""";
var flat = JsonFlattener.Flatten(json, "/");
// { "db/host": "localhost", "db/port": "5432" }

Unflatten

using Philiprehberger.FlattenJson;

var flat = new Dictionary<string, string?>
{
    ["db.host"] = "localhost",
    ["db.port"] = "5432"
};
var json = JsonFlattener.Unflatten(flat);
// {"db":{"host":"localhost","port":"5432"}}

API

JsonFlattener

Method Description
Flatten(string json, string separator = ".") Parse json and return a flat Dictionary<string, string?> using dot-notation keys
Unflatten(Dictionary<string, string?> flat, string separator = ".") Reconstruct a JSON string from a flat dictionary

Notes:

  • All leaf values are stored as strings (or null for JSON nulls).
  • Array elements are keyed by their zero-based index: "a.0", "a.1", etc.
  • Uses System.Text.Json — no external dependencies.

Development

dotnet build src/Philiprehberger.FlattenJson.csproj --configuration Release

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

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 was computed.  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.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.10 123 4/1/2026
0.1.9 115 3/27/2026
0.1.8 115 3/25/2026
0.1.7 115 3/23/2026
0.1.6 110 3/23/2026
0.1.5 109 3/20/2026
0.1.4 147 3/16/2026
0.1.3 132 3/16/2026
0.1.2 139 3/16/2026
0.1.1 141 3/11/2026
0.1.0 139 3/11/2026