A tiny language and engine for selecting specific parts of a JavaScript object while preserving its original structure.
JSON Mask is a lightweight JavaScript library that filters objects by selecting specific fields to keep, masking the rest. It solves the problem of efficiently retrieving partial data from HTTP resources without changing the original object's structure, similar to Google APIs' partial response feature.
Backend developers building HTTP APIs in Node.js who need to implement partial responses or optimize payload sizes by allowing clients to request only specific fields.
Developers choose JSON Mask for its simplicity, structure-preserving design, and seamless integration with existing HTTP services via middleware, avoiding the complexity of full query languages while reducing bandwidth usage.
Tiny language and engine for selecting specific parts of a JS object, hiding the rest.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The library is only 1.5KB gzipped and has no dependencies, making it easy to integrate into any Node.js or browser project, as stated in the README under cross-platform support.
Unlike JSONPath, it maintains the original object hierarchy, which is crucial for HTTP APIs where response structure must remain intact, as emphasized in the philosophy section.
Dedicated middleware packages for Express and Koa enable easy implementation of partial responses without altering existing code, as mentioned with express-partial-response and koa-json-mask.
Uses a simple XPath-like syntax with paths, wildcards, and sub-selections, allowing precise masking, as demonstrated in examples with commas, slashes, and parentheses.
Only supports selecting fields to keep, not filtering based on values or performing complex operations like comparisons, which may require additional libraries for advanced use cases.
Keys containing special characters require backslash escaping, which is error-prone in JavaScript strings where backslashes must be doubled, as noted in the escaping section with examples.
The mask syntax isn't validated; if specified fields don't exist, the behavior is undefined, and the README lacks guidance on handling such edge cases or performance impacts.