Skip to content

Instantly share code, notes, and snippets.

@mvsde
Last active August 26, 2019 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvsde/430d826cfa7c5ef1ce35a84c08622f7d to your computer and use it in GitHub Desktop.
Save mvsde/430d826cfa7c5ef1ce35a84c08622f7d to your computer and use it in GitHub Desktop.
Naive JSON.stringify() in Sass (handles strings only)
@function json-stringify ($map) {
$result: '{';
@each $key, $value in $map {
$result: $result + '"#{$key}":';
@if type-of($value) == 'map' {
$result: $result + json-stringify($value);
} @else {
$result: $result + '"#{$value}"';
}
@if index($map, ($key $value)) != length($map) {
$result: $result + ',';
}
}
$result: $result + '}';
@return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment