node-sass-json-importer provides a mechanism to import JSON and JSON5 files directly into Sass stylesheets when processed by `node-sass`. It allows `@import` rules in Sass to resolve to `.json` or `.json5` files, making it possible to define design tokens, configuration variables, or other data structures in JSON and consume them directly within Sass. The package's last stable version was 4.3.0, released in May 2020. Given its fundamental dependency on the deprecated `node-sass` library, active development has ceased, and new releases are not expected. Its primary differentiator was bridging the gap between JSON data sources and Sass compilation workflows using `node-sass`, offering features like case conversion and custom path resolution, but it is not compatible with modern `sass` (Dart Sass) setups.
npm install node-sass-json-importerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `node-sass-json-importer` with `node-sass` to process `.json` files within Sass, showing both asynchronous and synchronous `render` methods.
Migrate your project from `node-sass` to `sass` (Dart Sass). You will need to find an alternative JSON importer compatible with Dart Sass, such as `sass-json-vars` or implement a custom importer for Dart Sass.
Ensure JSON values are formatted like `"description": "'A sentence with spaces.'"` instead of `"description": "A sentence with spaces."`. This allows Sass to process the inner single-quoted string as a literal Sass string.
Upgrade to version 4.1.2 or later to ensure stability and correct behavior.
Change `importer: jsonImporter` to `importer: jsonImporter()` in your configuration.
In your JSON file, ensure that values intended to be unquoted Sass strings containing special characters are wrapped in single quotes, e.g., change `"key": "A value with spaces"` to `"key": "'A value with spaces'"`.
Ensure you invoke the importer factory function: use `importer: jsonImporter()` instead of `importer: jsonImporter`.
First, run `npm install node-sass-json-importer` or `yarn add node-sass-json-importer`. Then, verify that the import statement or path in your `sass-loader` or `node-sass` configuration correctly points to the installed package.