
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
sass-importer-json
Advanced tools
Dart Sass importer for reading values in JSON files into Sass/SCSS variables
Dart Sass importer for reading values in JSON files (or most other key-value-ish files) into Sass/SCSS variables.
npm install -D --production sass-importer-json
The default export is a function which takes an options object and returns an
importer. Add the returned importer to the importers array when you call
sass.compile or sass.compileAsync from the Dart Sass JS API.
extensions: Defaults to ['.json']. List of file extensions the importer
will recognize and attempt to load.parse: Defaults to JSON.parse, but can be any function which receives file
contents as a string and returns a value. Its return value will be read as a
dict whose entries will become the file's declared Sass variables.encoding: Defaults to 'utf-8' which is almost certainly what you want, but
you can pass any encoding Node supportsbuild.js:
import sass from 'sass';
import jsonImporter from 'sass-importer-json';
const output = sass.compile('style.scss', {
importers: [jsonImporter()],
});
// log it, write it, stick it in a stew
console.log(output.css);
data.json:
{
"foo": "i am a string",
"bar": 42
}
style.scss:
@use "data";
.something::after {
content: data.$foo;
font-size: daa.$bar * 1px;
}
Then, in your terminal:
$ node build.js
.something::after {
content: "i am a string";
font-size: 42px;
}
With the parse and extensions options, you can add support for importing
custom syntaxes like JSONC or JSON5, or even completely
different formats like YAML. Basically any format consisting of
key-value pairs can probably be used with this importer if you set an
appropriate parse function:
import {compile} from 'sass';
import jsonImporter from 'sass-importer-json';
import JSON5 from 'json5';
import JSONC from 'jsonc-parser';
import YAML from 'yaml';
const out = compile('style.scss', {
importers: [
jsonImporter({
extensions: ['.json', '.jsonc'],
parse: JSONC.parse,
}),
jsonImporter({
extensions: ['.json5'],
parse: JSON5.parse,
}),
jsonImporter({
extensions: ['.yml', '.yaml'],
parse: YAML.parse,
}),
],
});
You don't have to pass a library function directly to parse - you can also
write a custom function which takes a string and returns a file's contents. This
can be useful to pass custom options to other parsers, or to pass a reviver to
standard JSON.parse:
import {compile} from 'sass';
import jsonImporter from 'sass-importer-json';
import YAML from 'yaml';
const out = compile('style.scss', {
importers: [jsonImporter({
extensions: ['.yaml', '.yml'],
parse: value => YAML.parse(value, undefined, {stringKeys: true});
})],
});
npm run fmt to format code with dprintnpm run build to build the typescript thingyreadFileSync (is this important? what
does the actual dart sass file loader do for normal sass files?)color.scale() or whatever? unsure how important this is since you can
also just pass colors as number tuples or some other consistent value and
manually create the color values from those numbers from sass)FAQs
Dart Sass importer for reading values in JSON files into Sass/SCSS variables
We found that sass-importer-json demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.