{"library":"node-sass-json-functions","title":"Sass JSON Functions","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-sass-json-functions"],"cli":null},"imports":["import createJsonFunctions from 'node-sass-json-functions';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as sass from 'sass'; // or 'sass-embedded'\nimport createJsonFunctions from 'node-sass-json-functions';\n\n// A minimal SCSS file for demonstration\n// Save this as 'index.scss'\n/*\n$list: 1, 2, '3', (4, 5, 6), (foo: 'bar baz');\n$map: (foo: 1, bar: (2, 3));\n\nbody {\n\tcontent-list: json-encode($list);\n\tcontent-map: json-encode($map);\n\tcontent-decode-list: json-decode('[1,2,\"test\"]');\n}\n*/\n\n(async () => {\n  try {\n    const result = await sass.compileAsync('./index.scss', {\n      functions: { ...createJsonFunctions(sass) }\n    });\n    console.log(\"Sass Compilation Result:\");\n    console.log(result.css);\n    // Expected minimal output:\n    // body {\n    //   content-list: '[1,2,\"3\",[4,5,6],{\"foo\":\"bar baz\"}]';\n    //   content-map: '{\"foo\":1,\"bar\":[2,3]}';\n    //   content-decode-list: 1, 2, \"test\";\n    // }\n  } catch (error) {\n    console.error(\"Sass compilation failed:\", error);\n  }\n})();","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}