node-sass-json-functions provides utilities for JSON encoding and decoding within Sass stylesheets. Currently at stable version 5.0.2, the library typically sees updates tied to major Sass API changes or Node.js runtime requirements, with several releases over the past year. Its primary function is to bridge the gap between Sass data structures (lists, maps, colors, calculations, strings, numbers, booleans, nulls) and JSON strings. This allows developers to encode complex Sass data into JSON for use in CSS `content` properties, JavaScript interoperability, or other purposes, and subsequently decode JSON strings back into native Sass types. A key differentiator is its factory function approach (`createJsonFunctions`) that requires passing the `sass` or `sass-embedded` module reference, ensuring compatibility with the specific Sass implementation being used. This package is essential for projects needing to serialize or deserialize structured data directly within their Sass compilation process.
npm install node-sass-json-functionsVerified import paths — ran on the pinned version, not inferred.
This snippet demonstrates how to integrate `node-sass-json-functions` into a Sass compilation process using `sass.compileAsync`. It shows how to pass the Sass implementation to the function factory to register `json-encode` and `json-decode` functions within your Sass environment.
Update your import statements to use ECMAScript Modules (e.g., `import createJsonFunctions from 'node-sass-json-functions';`) and ensure your project's `package.json` specifies `"type": "module"` or uses `.mjs` files. Upgrade your Node.js runtime to at least v18.
Adjust your usage from `createJsonFunctions()` to `createJsonFunctions(sass)` or `createJsonFunctions(sassEmbedded)` where `sass` or `sassEmbedded` is your imported Sass module.
Ensure your project uses `sass` or `sass-embedded` version 1.45 or newer (for `node-sass-json-functions` v4.x) or version 1.97.3 or newer (for `node-sass-json-functions` v5.x). Check your `package.json` for correct peer dependency resolution.
Ensure your project is configured for ESM by adding `"type": "module"` to your `package.json` or by using `.mjs` file extensions. Also, change `require()` to `import` statements.
Pass the imported Sass module to the factory function, e.g., `functions: { ...createJsonFunctions(sass) }`.Verify that `functions: { ...createJsonFunctions(sass) }` is correctly included within the options object passed to your `sass.compileAsync` or `sass.compile` call, and that `createJsonFunctions` received the `sass` (or `sass-embedded`) module as an argument.