A high-performance .NET wrapper for simdjson v5.0.4, exposing the On-Demand API via a thin C ABI bridge.
SimdJson.Net— idiomatic C# API:SimdJsonParser,JsonDocument,JsonValue,JsonArray,JsonObject, plusNdjsonParserandJsonDocumentStreamfor in-memory document streams (whitespace, newline, RFC 7464, or comma delimited)
All native binaries are compiled from source via GitHub Actions — transparent, reproducible, and auditable.
// Thread-local shared parser — no allocation per call
using var doc = SimdJsonParser.Shared.Parse("""{"name":"Alice","age":30}""");
using var name = doc.GetField("name");
Console.WriteLine(name.GetString()); // Alice
// Parse from UTF-8 span (no transcoding; the bytes are copied into the document)
ReadOnlySpan<byte> utf8 = """{"x":1}"""u8;
using var doc2 = SimdJsonParser.Shared.Parse(utf8);
// Truly zero-copy: parse out of your own buffer, which must have
// SimdJsonParser.RequiredPadding bytes of slack after the JSON
using var doc3 = parser.ParseInPlace(paddedBuffer, jsonLength);
// NDJSON from memory, using simdjson's batching parser
List<long> ids = NdjsonParser.Parse(File.ReadAllBytes("events.ndjson"),
d => { using var v = d.GetField("id"); return v.GetInt64(); });
// Which SIMD kernel simdjson selected for this machine
Console.WriteLine(SimdJsonParser.ActiveImplementation); // e.g. "haswell"
// Async parse from stream
using var doc3 = await parser.ParseAsync(stream, cancellationToken);
// Iterate an array
using var arr = doc.GetField("items").GetArray();
foreach (var item in arr)
{
Console.WriteLine(item.GetString());
}
// Iterate an object
using var obj = doc.GetObject();
foreach (var prop in obj)
{
Console.WriteLine($"{prop.Name} = {prop.Value.GetInt64()}");
prop.Value.Dispose();
}
// JSON Pointer
using var city = doc.AtPointer("/address/city");
// Chain indexers
using var val = doc["address"]["city"];
// Get simdjson version
Console.WriteLine(SimdJsonParser.GetVersion()); // e.g. "5.0.4"dotnet add package SimdJson.NetFull API reference and design notes live in the docs/ folder:
| Document | Contents |
|---|---|
| docs/API.md | API index, quick-lookup cheatsheet |
| docs/SimdJsonParser.md | Parser — Parse, ParseAsync, utilities |
| docs/JsonDocument.md | Document root — field access, pointers, rewind |
| docs/JsonValue.md | Value — scalar getters, numbers, raw JSON |
| docs/JsonArray.md | Array — iteration, index access, Count, IsEmpty |
| docs/JsonObject.md | Object — GetField, FindField, ContainsKey, iteration |
| docs/Numbers.md | JsonNumberType, JsonNumber struct |
| docs/NdjsonParser.md | NDJSON — streaming, parallel, and in-memory iterate_many batching |
| docs/Types.md | JsonValueKind, JsonProperty, SimdJsonException error codes |
| docs/DesignNotes.md | Thread safety, forward-only iteration, dispose rules, pitfalls |
The Samples/ folder contains runnable console projects, each demonstrating a different part of the API. After building the native library (see Building the Native Library Locally), run any sample with dotnet run --project Samples/<name>.
| Sample | What it covers |
|---|---|
| 01-BasicParsing | Parse(string), Parse(ReadOnlySpan<byte>), scalar field reads, indexer syntax, GetVersion() |
| 02-ArrayIteration | foreach, At(index), ElementAt, Count, IsEmpty, nested arrays, array of objects |
| 03-ObjectIteration | foreach JsonProperty, GetField/FindField/FindFieldUnordered, TryGetField, ContainsKey, dynamic ValueKind switch |
| 04-JsonPointerAndPath | RFC 6901 AtPointer, AtPath, TryAtPointer/TryAtPath on document / value / array / object |
| 05-NumberTypes | GetNumberType, GetNumber → JsonNumber, IsNegative/IsInteger, GetRawJsonToken, numbers-in-strings helpers |
| 06-StreamParsing | ParseAsync(Stream), ParseAsync(string), FileStream, CancellationToken |
| 07-ZeroAllocation | GetStringSpan, UTF-8 literal parse, ReadOnlySpan<byte> comparison, GetRawJsonTokenSpan, Minify, ValidateUtf8 |
| 08-ErrorHandling | SimdJsonException error codes, lazy On-Demand parse errors, TryXxx non-throwing API, ParseAllowIncompleteJson |
| 09-RealWorld-GeoJson | GeoJSON FeatureCollection — nested objects/arrays, bounding-box calculation, On-Demand forward-iteration discipline |
| 10-RealWorld-LogParser | NDJSON log stream — parser reuse across lines, aggregation, TryGetField for optional fields |
| 11-WildcardAndRawString | ForEachAtPath wildcard JSONPath iteration; GetRawJsonString/GetRawJsonStringSpan for escaped-byte access |
| 12-DocumentScalarsAndCounting | Root scalar getters, At(index), CountElements/CountFields, number-in-string getters |
| 13-NdjsonParsing | NdjsonParser.ParseAsync/ParseParallelAsync/ForEachAsync over a stream, NdjsonParserOptions, CRLF and BOM edge cases |
On-Demand iteration tip: simdjson On-Demand is a forward-only streaming parser. Always fully consume a nested object or array before accessing the next sibling field in its parent. See samples 09 and 10 for patterns.
The runtimes/ folder is not checked in. After cloning, you need to build the native library before the .NET project will work.
Open the solution — the SimdJson.Net.Native/ solution folder contains the CMake project. VS 2022 detects CMakePresets.json automatically.
- Select the Debug (win-x64) preset in the CMake toolbar (top of the IDE).
- Build → Build All to compile the native library.
- Build → Install SimdJsonNative to run
cmake --install— this writesSimdJsonNative.dlldirectly intoSimdJson.Net/runtimes/win-x64/native/. - Build / run the .NET project normally.
The install step is required once after every CMake rebuild. Steps 2 and 3 can also be triggered by right-clicking
CMakeLists.txtin Solution Explorer.
RID=win-x64 # or linux-x64, osx-arm64, etc.
INSTALL_DIR="$(pwd)/SimdJson.Net/runtimes/$RID/native"
mkdir -p "$INSTALL_DIR"
cmake -S SimdJson.Net.Native -B SimdJson.Net.Native/build \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR"
cmake --build SimdJson.Net.Native/build
cmake --install SimdJson.Net.Native/buildThen dotnet build / dotnet test as normal.
The native SimdJsonNative shared library wraps simdjson by Daniel Lemire and contributors, licensed under Apache 2.0. This package is an independent .NET distribution; all simdjson rights belong to the original authors.
- Upstream: https://github.com/simdjson/simdjson
- This repository: https://github.com/zcsizmadia/SimdJson.Net
MIT. See LICENSE.
