JSON Mirror Compiler
raw JSON → 0.4.12 verified Fri May 01 auth: no javascript
json-mirror-compiler is a TypeScript library (v0.4.12, pre-1.0, monthly releases) that compiles JSON Mirror specifications into executable code. It provides a compile function to transform JSON Pointer-based schema definitions into runtime implementations. Key differentiator: focuses on mirror patterns for bidirectional data mapping, unlike other JSON Pointer tools that only resolve paths. Ships TypeScript types.
Common errors
error Cannot find module 'json-mirror-compiler' ↓
cause Package not installed or mismatched version.
fix
Run
npm install json-mirror-compiler@0.4.12 and ensure node_modules includes it. error SyntaxError: The requested module 'json-mirror-compiler' does not provide an export named 'compile' ↓
cause Using a CommonJS require() which doesn't work with ESM-only packages.
fix
Change to
import { compile } from 'json-mirror-compiler'. error TypeError: compile is not a function ↓
cause Using the return value of compile incorrectly (expecting object instead of function) since v0.4.0.
fix
Ensure you call the compiled function: compile(spec)(input) or const fn = compile(spec); fn(input).
error Cannot read properties of undefined (reading 'jsonPointer') ↓
cause Passing an incomplete spec object without source or target fields.
fix
Make sure spec has both 'source' and 'target' objects with 'jsonPointer' strings.
Warnings
gotcha Package is pre-1.0 (v0.4.12); API may change without major version bump. ↓
fix Pin exact version in package.json and review changelog before updating.
gotcha Known breaking change in v0.4.0: Return type of compile changed from object to function. ↓
fix Update code to treat compile() output as a function rather than a static object.
gotcha ESM-only package; CommonJS require will throw an error. ↓
fix Use ES import syntax or switch to a dynamic import if in a CommonJS context.
gotcha TypeScript types shipped but may be incomplete in some versions. ↓
fix Check type definitions at node_modules/json-mirror-compiler/dist/index.d.ts; contribute fixes if needed.
Install
npm install json-mirror-compiler yarn add json-mirror-compiler pnpm add json-mirror-compiler Imports
- compile wrong
const compile = require('json-mirror-compiler')correctimport { compile } from 'json-mirror-compiler' - default export wrong
const jsonMirrorCompiler = require('json-mirror-compiler')correctimport jsonMirrorCompiler from 'json-mirror-compiler' - MirrorSpec type wrong
import { MirrorSpec } from 'json-mirror-compiler'correctimport type { MirrorSpec } from 'json-mirror-compiler'
Quickstart
import { compile } from 'json-mirror-compiler';
const spec = {
source: { jsonPointer: '/data' },
target: { jsonPointer: '/mirrored' }
};
const compiledFn = compile(spec);
const result = compiledFn({ data: { value: 42 } });
console.log(JSON.stringify(result)); // {"mirrored":{"value":42}}