fastjsond 1.0.1

High-performance JSON parser for D, wrapping simdjson


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

fastjsond

High-performance JSON parser for D.

Built on simdjson, the SIMD-accelerated JSON parser.

DUB License D

Overview

fastjsond provides two APIs:

  • Native API: Zero-copy parsing with maximum performance
  • std.json-compatible API: Drop-in replacement with faster execution

SIMD instruction sets (AVX2, SSE4.2, NEON) are auto-detected at runtime.

Installation

Add to your dub.json:

"dependencies": {
    "fastjsond": "~>1.0.0"
}

Or with dub.sdl:

dependency "fastjsond" version="~>1.0.0"

Building from Source

git clone https://github.com/federikowsky/fastjsond.git
cd fastjsond
make lib    # Build static library
make test   # Run tests

Quick Start

Drop-in Replacement for std.json

import fastjsond.std;  // Change import from std.json

auto json = parseJSON(`{"name": "Aurora", "version": 2}`);
string name = json["name"].str;
long ver = json["version"].integer;

Native Zero-Copy API

import fastjsond;

auto parser = Parser.create();
auto doc = parser.parse(`{
    "name": "Aurora",
    "version": 2,
    "features": ["fast", "safe"]
}`);

if (!doc.valid) {
    writeln("Error: ", doc.errorMessage);
    return;
}

// Zero-copy: getString returns slice into original buffer
const(char)[] name = doc.root["name"].getString;
long ver = doc.root["version"].getInt;

// Iteration
foreach (feature; doc.root["features"]) {
    writeln(feature.getString);
}

API Reference

Native API (fastjsond)

Parser

auto parser = Parser.create();  // Reusable parser instance
auto doc = parser.parse(jsonString);
auto doc = parser.parsePadded(paddedBuffer);  // Pre-padded input

Document

if (doc.valid) {
    auto root = doc.root;
}
string err = doc.errorMessage;

Value

// Type access
bool   b = value.getBool();
long   n = value.getInt();
ulong  u = value.getUint();
double d = value.getDouble();
const(char)[] s = value.getString();  // Zero-copy

// Safe extraction
if (auto result = value.tryInt()) {
    writeln("Value: ", result.value);
}

// Navigation
auto field = root["key"];        // Object field
auto item = root["items"][0];    // Array element

// Iteration
foreach (item; root["array"]) { }
foreach (key, val; root["object"]) { }

std.json-Compatible API (fastjsond.std)

import fastjsond.std;

auto json = parseJSON(jsonString);
string name = json["name"].str;
long count = json["count"].integer;
double price = json["price"].floating;

if (auto ptr = "optional" in json) {
    writeln(ptr.str);
}

Module Functions

import fastjsond;

bool ok = validate(jsonString);              // Validate without parsing
size_t padding = requiredPadding();          // Get padding requirement
string impl = activeImplementation();        // "haswell", "arm64", etc.

Performance

Benchmarked on Apple M1:

Payloadstd.jsonfastjsondSpeedup
1 MB8.45 ms0.59 ms14x
10 MB82 ms6.8 ms12x
100 MB818 ms126 ms6.5x

Error detection:

Error Typestd.jsonfastjsondSpeedup
Invalid syntax0.75 ms0.008 ms93x
Invalid escapes0.86 ms0.004 ms210x

String Lifetime

Native API strings are borrowed references into the original buffer:

// Incorrect: reference invalid after doc goes out of scope
const(char)[] getName() {
    auto doc = parser.parse(`{"name": "test"}`);
    return doc.root["name"].getString;  // Dangling reference
}

// Correct: copy the string
string getName() {
    auto doc = parser.parse(`{"name": "test"}`);
    return doc.root["name"].getString.idup;
}

// Alternative: use std API (auto-copies)
import fastjsond.std;
string getName() {
    auto json = parseJSON(`{"name": "test"}`);
    return json["name"].str;
}

Building

Requirements

  • D Compiler: LDC 1.35+ (recommended) or DMD 2.105+
  • C++ Compiler: clang++ or g++ (C++17)

Make Targets

TargetDescription
make libBuild libfastjsond.a
make testRun all tests
make benchRun benchmarks
make cleanClean artifacts

Documentation

Contributing

Contributions are welcome. Please ensure:

  1. Tests pass (make test)
  2. Benchmarks do not regress
  3. Code follows D style guidelines

License

MIT License — see LICENSE for details.

Authors:
  • Federico Filippi
Dependencies:
none
Versions:
1.0.1 2025-Dec-07
1.0.0 2025-Dec-07
~main 2025-Dec-07
Show all 3 versions
Download Stats:
  • 3 downloads today

  • 7 downloads this week

  • 7 downloads this month

  • 7 downloads total

Score:
0.3
Short URL:
fastjsond.dub.pm