A tiny language and engine for selecting specific parts of a JavaScript object, hiding the rest. Version 2.0.0 is the latest stable release. It preserves the original object structure, unlike JSONPath or JSONSelect. Designed for HTTP partial responses (like Google APIs' ?fields= query). No dependencies, works in Node.js and browsers. Maintained with infrequent releases. Key differentiator: keeps the structure intact instead of flattening results.
npm install json-maskNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates masking an object by selecting specific fields (name, nested city, and array roles) while preserving structure.
Use import mask from 'json-mask' or update Node.js to version supporting ESM. For CommonJS projects, use dynamic import or upgrade to Node 14+ with --experimental-modules.
Remove the third argument from mask() calls. If you relied on options, handle them via the fields string (e.g., use nested paths).
Escape special characters in field names using backslash, e.g., 'a\.b' for field 'a.b'.
Use explicit paths for deeper nesting, e.g., 'a/*/b' instead of expecting 'a/*' to recurse.
Change to: const mask = require('json-mask') or import mask from 'json-mask'Use const mask = require('json-mask') or switch to ESM by adding "type": "module" in package.jsonEscape dots with backslash: 'a\.b' for field 'a.b'. Double-check field names match exactly.