1.5.1 • Public • Published

Contributors Forks Stargazers Issues MIT License LinkedIn



It's an utility package that converts any JSON stream into Sass maps with additional color convertion. new-badge

View Changelog · View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. API
  5. Roadmap
  6. Contributing
  7. License
  8. Contact
  9. Acknowledgments
  10. Donate

About The Project

Product Name Screen Shot

There are lots of Json-sass package available on npm; however, I didn't find one that really suited my needs. So, I thought of creating one. Altough, i find one that's good enough & made by Andrew Clark. But that wasn't maintained from last 6+ years.

This is an Utility module that converts a JSON stream into sass maps. It can be used as whitelabeling themes, fonts etc.

Here's why it's best:

  • firstly, you can share values between your scripts and stylesheets without having to use something like SassyJSON, which doesn't work with libsass.
  • json2scss-map converts JSON objects into Sass maps, which are supported in Ruby Sass 3.3 and libsass 2.0. & latest Dart Sass.
  • Also, New Version includes color convertions to HEX, HSL, RGB 😎

(back to top)

Built With

This is a very small package without any major dependency. However, we use some packages for giving support for browser-compatible Javascript, Unit testing etc.

(back to top)

Getting Started

It's very easy to use this plugin, instructions are mentioned below or you can View Demo.


There no such basic requirements only node.js should be installed. also update npm or yarn if you can. Although, there are some issue in node 17.


There are many ways to install this plugin mentioned below.

  • using npm:
    npm i -D json2scss-map
  • using yarn:
    yarn add json2scss-map -D

(back to top)


Example source file theme.json:

Input Json

From the command-line:

$ json2scss-map -i theme.json -o theme.scss -p "\$variable: " -t hex

CLI Options:

  • -i, --infile: (Default: standard input stdin) Specify the input file.
  • -o, --outfile: (Default: standard output stdout) Designate the output SCSS file.
  • -p, --prefix: Set a prefix for all SCSS variables.
  • -s, --suffix: Set a suffix for all SCSS variables.
  • -c, --colorConversion: (Default: true) Enable or disable color conversion.
  • -t, --convertTo: (Default: 'hsl') Specify the color format (e.g., hsl, hex, rgb).
  • -l, --cl4Syntax: (Default: false) Use cl4 syntax if applicable.

Output theme.scss with new color convertion to hsl by default:

Output Scss map

Or you can use the Node API: (recommended)

var fs = require('fs');
var json2scss = require('json2scss-map');

    prefix: '$variable: ',
    cl4Syntax: true

Then, you can get the values from scss:map

  $color-primary: map-get(map-get($variable, "theme"), "primary"); // hsl(211, 100%, 50%)
  $font-main: map-get($variable, "fs-main"); // "Mulish"

You can also transform normal JavaScript values using the exposed utility function:

json2scss.convertJs([1, 2, 3]); // (1, 2, 3)

For more, please refer to the View Demo

Alternatively, If you're using custom Webpack Configuration, you can use this tool to easily import JSON files and get the correct values. Json2scss-map-webpack-importer

(back to top)



Returns a through stream. Available options:

  • prefix: Add some text to the beginning
  • suffix: Add some text to the end. Defaults to ';'.
  • colorConversion: New Feature to convert only colors value to different color scheme. Defaults to true. (from v1.5.0)
  • convertTo: Right now support convertion for HSL, RGB, HEX colors. Defaults to hsl.
  • cl4Syntax: color lavel 4 new syntax with space separator for the output. Defaults to false.


Convert a normal JavaScript value to its string representation in Sass. Ignores undefined and functions. Calls .toString() on non-plain object instances.


  • [x] Add Changelog
  • [x] Add new Color label 4 syntax support
  • [x] Add Color Convertion to (hsl, rgb, hex)
  • [ ] Add support for Color Lavel 4 Syntax in input stream as well.
  • [ ] Add Support for LCH color scheme convertion.
  • [ ] Add Support for % value in RGB colors.
  • [ ] Add Support for turn, deg, rad etc unit support in hsl & rgb colors.

See the open issues for a full list of proposed features (and known issues).

(back to top)


Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this plugin better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star ⭐️! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/{feature-name})
  3. Commit your Changes (git commit -m 'Add some {feature}')
  4. Push to the Branch (git push origin feature/{feature-name})
  5. Open a Pull Request
  6. You're awesome.

(back to top)


Distributed under the MIT License. See LICENSE for more information.
AS Developers


Susanta Chakraborty - @susantaChak

Project Link: https://github.com/AS-Devs/json2scss-map

(back to top)


There are lots of people to acknowledge. I've included few of them to help be build this plugin.


If you found this project helpful or you learned something from the source code and want to thank me, consider buying me a cup of 🍵

(back to top)

Package Sidebar


npm i json2scss-map

Weekly Downloads






Unpacked Size

454 kB

Total Files


Last publish


  • susanta96
  • ayanab