| Crates.io | unbinder |
| lib.rs | unbinder |
| version | 0.1.7 |
| created_at | 2025-08-05 19:14:12.583968+00 |
| updated_at | 2025-08-05 19:14:12.583968+00 |
| description | A high-performance JSON Schema dereferencer for resolving $ref pointers |
| homepage | https://github.com/jakobloch/unbinder |
| repository | https://github.com/jakobloch/unbinder |
| max_upload_size | |
| id | 1782599 |
| size | 46,319 |
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.
no_std support[dependencies]
unbinder = "0.1.7"
npm install unbinder
use unbinder::{dereference_schema, Options};
use serde_json::json;
fn main() -> Result<(), unbinder::Error> {
let mut schema = json!({
"type": "object",
"properties": {
"name": { "$ref": "#/definitions/name" },
"age": { "$ref": "#/definitions/age" }
},
"definitions": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
}
});
// Dereference with default options
dereference_schema(&mut schema, Options::default())?;
// Or with custom options
let opts = Options {
resolve_external: false,
on_circular: Some(|path| println!("Circular reference detected: {}", path)),
};
dereference_schema(&mut schema, opts)?;
println!("{}", serde_json::to_string_pretty(&schema)?);
Ok(())
}
Important: WebAssembly modules must be initialized before use
import init, { dereferenceSchema, Options } from "unbinder";
// Initialize the WASM module (required!)
await init();
const schema = {
type: "object",
properties: {
name: { $ref: "#/definitions/name" },
age: { $ref: "#/definitions/age" },
},
definitions: {
name: { type: "string" },
age: { type: "integer", minimum: 0 },
},
};
// Create options (optional)
const options = new Options();
options.logCircularRefs = true;
// Dereference the schema
const dereferenced = dereferenceSchema(schema, options);
console.log(JSON.stringify(dereferenced, null, 2));
<script type="module">
import init, {
dereferenceSchema,
Options,
} from "./node_modules/unbinder/unbinder.js";
async function run() {
// Initialize WASM
await init();
// Now you can use dereferenceSchema
const result = dereferenceSchema(mySchema);
}
run();
</script>
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);
}
}
}
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 behaviorOptionspub struct Options {
pub resolve_external: bool, // Whether to resolve external references
pub on_circular: Option<fn(&str)>, // Callback for circular references
}
count(v: &Value) -> (usize, usize, usize)Returns statistics about the JSON structure:
$ref referencesdereferenceSchema(value: any, options?: Options): anyDereferences all $ref pointers in the given JSON object.
Options classclass Options {
constructor()
setResolveExternal(value: boolean): void
setLogCircularRefs(value: boolean): void
}
estimateSchemaSize(json: string): objectReturns statistics about the JSON structure:
{
bytes: number, // Size in bytes
objects: number, // Number of objects
arrays: number, // Number of arrays
refs: number // Number of $ref references
}
cargo build --release
# Install wasm-pack if not already installed
cargo install wasm-pack
# Build the WASM module
wasm-pack build --target web --out-dir pkg
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 WASMUnbinder is optimized for performance:
FxHashMap for faster hash operationsno_std environments for embedded use#)Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Jakob Lochinski