Registry / storage / jsonschema-key-compression

jsonschema-key-compression

JSON →
library1.7.0jsnpmunverified

Compress JSON data based on its JSON Schema by replacing long attribute names with shorter ones. Version 1.7.0 is stable, actively maintained, and ships TypeScript types. Key differentiator: it preserves valid JSON structure, making it suitable for storage in NoSQL databases or browser storage where gzip is inefficient on small payloads. Provides 40% size reduction on average. Does not require a build step or schema transformation.

npm install jsonschema-key-compression
INSTALL
IMPORT
SIG · JSONSCHEMA-KEY-COM
J
jsonschema-key-compression
storagejavascriptv1.7.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createCompressionTable
import { createCompressionTable } from 'jsonschema-key-compression'
ESM-only. No CommonJS support.
compressObject
import { compressObject } from 'jsonschema-key-compression'
Requires a compression table from createCompressionTable.
decompressObject
import { decompressObject } from 'jsonschema-key-compression'
Requires the same compression table used for compression.
compressedPath
import { compressedPath } from 'jsonschema-key-compression'
Transforms dot-separated paths to compressed form.
decompressedPath
import { decompressedPath } from 'jsonschema-key-compression'
Reverses compressed path back to original.

Shows full round-trip: schema -> compression table -> compress object -> decompress object.

import { createCompressionTable, compressObject, decompressObject } from 'jsonschema-key-compression'; const schema = { type: 'object', properties: { firstName: { type: 'string' }, lastName: { type: 'string' }, age: { type: 'number' } }, required: ['firstName', 'lastName', 'age'] }; const data = { firstName: 'John', lastName: 'Doe', age: 30 }; const table = createCompressionTable(schema); const compressed = compressObject(table, data); console.log(compressed); // e.g., { "|a": "John", "|b": "Doe", "|c": 30 } const decompressed = decompressObject(table, compressed); console.log(decompressed); // { firstName: 'John', lastName: 'Doe', age: 30 }
Debug
Known issues
gotchaCompression table must be created from the exact schema used for the data. Using a different schema will produce incorrect compressed output.
fix
Always use the same schema object for createCompressionTable as the data conforms to.
affects: >=1.0
gotchaThe compression algorithm only shortens object keys. Values are left untouched. Expect minimal savings on arrays of primitive values.
fix
Consider additional compression (e.g., gzip) for value-heavy payloads.
affects: >=1.0
gotchaThe compressed output is still valid JSON, but property names become short tokens (e.g., '|a'). This may break code that relies on specific key names for lookups.
fix
Always decompress before using the data in logic that depends on original key names.
affects: >=1.0
deprecatedNo known deprecated APIs in current version.
fix
N/A
affects: 1.7.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'properties' of 'schema' as it is undefined.
Passing a schema without a 'properties' field or incorrectly structured schema.
fix
Ensure the schema is a valid JSON Schema object with a 'properties' key for objects, or use a schema that defines the object structure explicitly.
Error: Schema is not an object
createCompressionTable called with a non-object (e.g., string or number).
fix
Pass a valid JSON Schema object to createCompressionTable.
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
jsonschema-key-compression — npm install jsonschema-key-compression · libregistry