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.
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.
res.xJson(massiveDataset, {
enableStreaming: true,
chunkSize: 1024 * 128 // Custom 128KB chunks
});API Reference
| Option | Default | Description |
|---|---|---|
| maxDepth | 20 | Maximum recursion level for object graphs. |
| truncateStrings | 10000 | Character limit before string truncation. |
| enableStreaming | true | Enable chunk-based response delivery. |
| chunkSize | 64KB | Size of each stream chunk in bytes. |
| includeNonEnumerable | false | Whether 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
Learn about robust real-client IP resolution across proxies and VPNs.
