Mugi.Json 0.1.3

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

Mugi.Json

Mugi.Json is the NativeAOT-compatible JSON serializer used by the Mugi web framework. It reads and writes JSON through per-type codecs registered ahead of time, so serialization works without reflection or runtime code generation.

In a Mugi application you normally never call this package directly: the Mugi.Generators package writes a codec for every type your handlers serialize, and c.Json(...) and c.Req.Json<T>() use them. Reference this package on its own when you need the serializer outside a handler or want to write a codec by hand.

Serialize and deserialize

using System.Buffers;
using Mugi.Json;

var buffer = new ArrayBufferWriter<byte>();
Json.Serialize(buffer, new User("42", "Ada"));

var user = Json.Deserialize<User>(buffer.WrittenSpan);

public sealed record User(string Id, string Name);

Json.Serialize<T> writes UTF-8 JSON to any IBufferWriter<byte>, and Json.Deserialize<T> parses a ReadOnlySpan<byte>. Both take an optional JsonOptions. A codec for T must be registered first; in a Mugi app the generator does this for the types it sees at call sites, and Json.Include<T>() covers a type reached only through generics.

Writing a codec by hand

Implement IJsonCodec<T> and register it with Json.Register. A registered codec is used everywhere that type is serialized. JsonWriter and JsonReader are ref struct types over the output buffer and input span, with methods such as WriteString, WriteNumber, WriteRaw, ReadBeginObject, ReadPropertyName, and SkipValue.

using Mugi.Json;

Json.Register(UserCodec.Instance);

Limits for untrusted input

Parsing enforces limits so hostile JSON cannot exhaust memory or the stack: document size, nesting depth, string length, collection size, and number length are all capped through JsonOptions. NaN and Infinity are rejected by default.

Full documentation is at github.com/hckaye/Mugi.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.
  • net9.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Mugi.Json:

Package Downloads
Mugi

A fast, simple web application framework for .NET, built for Native AOT.

Mugi.Jwt

Native AOT-compatible JWT signing, validation, and authentication middleware for Mugi.

Mugi.Schema

Typed request binding and validation for Mugi.

Mugi.Reflection

Opt-in reflection-based JSON codecs for Mugi.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.3 149 8/28/2026
0.1.2 134 8/28/2026