Unbinder
A high-performance JSON Schema dereferencer written in Rust with WebAssembly
support. Unbinder resolves $ref pointers in JSON Schema documents, making them
self-contained by replacing references with their actual content.
Features
- 🚀 Fast - Written in Rust for maximum performance
- 🌐 WebAssembly Support - Use in browsers and Node.js environments
- 🔄 Circular Reference Detection - Handles circular references gracefully
- 🎯 Zero Dependencies - Minimal footprint with
no_stdsupport - 🔧 Flexible - Available as both Rust crate and npm package
Installation
As a Rust Crate
[]
= "0.1.7"
As an npm Package
Usage
Rust
use ;
use json;
JavaScript/TypeScript
Important: WebAssembly modules must be initialized before use
import init from "unbinder";
// Initialize the WASM module (required!)
await ;
const schema = ;
// Create options (optional)
const options = ;
options. = true;
// Dereference the schema
const dereferenced = ;
console.log;
Browser Usage
TypeScript
The package includes TypeScript definitions:
import init, { dereferenceSchema, Options, WasmError } from "unbinder";
async function processSchema() {
// Initialize WASM first
await init();
try {
const result = dereferenceSchema(schema, new Options());
return result;
} catch (error) {
if (error instanceof WasmError) {
console.error("Dereferencing failed:", error.message);
}
}
}
API Reference
Rust API
dereference_schema(root: &mut Value, opts: Options) -> Result<(), Error>
Dereferences all $ref pointers in the given JSON value in-place.
root: The JSON value to dereference (modified in-place)opts: Options for controlling the dereferencing behavior
Options
count(v: &Value) -> (usize, usize, usize)
Returns statistics about the JSON structure:
- Number of objects
- Number of arrays
- Number of
$refreferences
JavaScript API
dereferenceSchema(value: any, options?: Options): any
Dereferences all $ref pointers in the given JSON object.
Options class
estimateSchemaSize(json: string): object
Returns statistics about the JSON structure:
Building from Source
Prerequisites
- I have only used with Rust 1.88, it might work for earlier versions
- wasm-pack (for WebAssembly builds)
- Node.js (for npm package)
Building the Rust Crate
Building the WebAssembly Module
# Install wasm-pack if not already installed
# Build the WASM module
Features
The crate supports several feature flags:
std(default): Standard library supportwasm: WebAssembly bindingsparallel: Parallel processing supportconsole_log: Console logging in WASMwee_alloc: Use wee_alloc as the global allocatortext-interface: String-based API for WASM
Performance
Unbinder is optimized for performance:
- Uses
FxHashMapfor faster hash operations - Implements zero-copy parsing where possible
- Supports
no_stdenvironments for embedded use - Optional parallel processing for large schemas
- Tiny WASM bundle size with wee_alloc
Limitations
- Currently only supports internal references (starting with
#) - External references (URLs) are not yet supported
- JSON Pointer syntax follows RFC 6901
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Jakob Lochinski