Cocoar.Json.Mutable 1.0.0

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

Cocoar.Json.Mutable

Fast. Mutable. Merge-Focused.

A high-performance mutable JSON document object model (DOM) optimized for merging multiple JSON objects efficiently. Built on UTF-8 byte arrays for zero-overhead string handling.

Why Use This?

Problem: Most JSON libraries either:

  • Offer immutable structures (hard to modify/merge)
  • Use managed strings (overhead for large documents)
  • Lack efficient deep-merge capabilities

Solution: Cocoar.Json.Mutable provides a mutable JSON DOM that:

  • Stores content as UTF-8 byte[] for performance
  • Supports efficient deep merging of JSON objects
  • Allows in-place modifications
  • No security overhead from memory zeroing

Key Features

Mutable JSON structure - Create, modify, and merge JSON documents in-memory
UTF-8 native - Works directly with UTF-8 bytes using ReadOnlySpan<byte> and ReadOnlyMemory<byte>
Efficient deep merge - Merge multiple JSON objects with recursive merging
High performance - No unnecessary memory zeroing or security overhead
Built on System.Text.Json - Uses Utf8JsonReader and Utf8JsonWriter
Provider-friendly - Accepts ReadOnlyMemory<byte> from data providers

Quick Start

using Cocoar.Json.Mutable;

// Create an empty document
var doc = new MutableJsonObject();

// Parse from ReadOnlySpan<byte> or ReadOnlyMemory<byte>
var config1 = MutableJsonDocument.Parse("{\"server\": {\"port\": 8080}}"u8);
var config2 = MutableJsonDocument.Parse("{\"server\": {\"host\": \"localhost\"}, \"debug\": true}"u8);

// Or from ReadOnlyMemory<byte> (perfect for providers!)
ReadOnlyMemory<byte> memoryFromProvider = GetJsonFromProvider();
var config3 = MutableJsonDocument.Parse(memoryFromProvider);

// Merge them together
MutableJsonMerge.Merge(doc, (MutableJsonObject)config1);
MutableJsonMerge.Merge(doc, (MutableJsonObject)config2);

// Result: {"server": {"port": 8080, "host": "localhost"}, "debug": true}

// Developer-friendly string API
doc.Set("version", new MutableJsonString("1.0.0"));
doc.Set("maxConnections", new MutableJsonNumber(100));
doc.Set("enabled", new MutableJsonBool(true));

// Get values using strings (much easier!)
var serverNode = doc.Get("server") as MutableJsonObject;
var port = serverNode?.Get("port") as MutableJsonNumber;

// Or use UTF-8 bytes for zero allocations
var versionNode = doc.Get("version"u8);

// Serialize to JSON
var jsonBytes = MutableJsonDocument.ToUtf8Bytes(doc);

Merge Strategies

// Non-destructive merge (clones source values)
MutableJsonMerge.Merge(target, source);

// Destructive merge (moves source values, faster)
MutableJsonMerge.MergeDestructive(target, source);

// Clone nodes when needed
var cloned = MutableJsonMerge.Clone(original);

Use Cases

  • Configuration merging (base config + environment overrides + user settings)
  • API response aggregation
  • JSON document transformations
  • Building complex JSON structures programmatically

When NOT to Use This

  • If you need immutable JSON structures (use System.Text.Json.JsonDocument)
  • If you're handling sensitive data that must be securely erased from memory (this library does NOT provide memory zeroing)
  • If you only need to read JSON once without modifications (use Utf8JsonReader directly)
  • If you need thread-safe concurrent access (this library is NOT thread-safe - use external synchronization if sharing instances across threads)

License

See LICENSE file for details.

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 (1)

Showing the top 1 NuGet packages that depend on Cocoar.Json.Mutable:

Package Downloads
Cocoar.Configuration

Reactive, strongly-typed configuration layering for .NET with health monitoring, file resilience, and zero-downtime updates. Core library providing ConfigManager, providers (file, environment, command-line, observable), and differential updates.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 211 11/15/2025
0.1.0-alpha.9 489 11/10/2025
0.1.0-alpha.8 203 11/10/2025