HTTP Server

XyPriss JSON (XJson) API

Robust JSON serialization engine designed to handle BigInt, circular references, and massive datasets without memory limitations.

The XJson API is an advanced response handler that solves the fundamental limitations of standard JSON.stringify(). By leveraging native Go serialization routines and streaming logic, it provides a fail-safe mechanism for complex data structures.

BigInt Support

Automatically serializes BigInt values to strings without throwing errors.

Circular Safe

Detects and handles cyclic object structures to prevent infinite recursion.

Streaming I/O

Streams responses in chunks for large datasets to avoid memory pressure.

Depth Control

Configurable recursion limits to protect server resources.

Basic Usage

Switch from res.json() to res.xJson() to benefit from enhanced serialization.

typescript
app.get("/api/stats", (req, res) => {
    const data = {
        id: "cmj17...",
        size: 18n, // BigInt - normally fails in JSON.stringify
        metadata: { author: "John" }
    };

    // Use XJson for safe delivery
    res.xJson(data);
});

Streaming Large Data

XJson automatically enables streaming for payloads exceeding **64KB**. This prevents the server from buffering the entire response in memory, ensuring stability under heavy load.

typescript
res.xJson(massiveDataset, {
    enableStreaming: true,
    chunkSize: 1024 * 128 // Custom 128KB chunks
});

API Reference

OptionDefaultDescription
maxDepth20Maximum recursion level for object graphs.
truncateStrings10000Character limit before string truncation.
enableStreamingtrueEnable chunk-based response delivery.
chunkSize64KBSize of each stream chunk in bytes.
includeNonEnumerablefalseWhether to serialize hidden properties.

Comparison Table

Standard JSON

  • Fails on BigInt
  • Crashes on Circular Refs
  • Buffers entire data in RAM
  • Strict Depth Limit (No Config)

XyPriss XJson

  • Native BigInt conversion
  • Cyclic detection & handling
  • Smart Streaming (>64KB)
  • Developer-defined depth
Client IP Detection

Learn about robust real-client IP resolution across proxies and VPNs.