Created
May 31, 2017 07:50
-
-
Save d-asensio/bc12c027bafddf19167264d5291d9253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@function valueToJSON($value, $key) { | |
$is_first_value: true; | |
$json_string: '{#{$key}:{'; | |
@if (type-of($value) == 'map') { | |
$json_string: $json_string + '{'; | |
@each $_key, $_value in $value { | |
@if not($is_first_value) { | |
$json_string: $json_string + ','; | |
} | |
$json_string: $json_string + '"#{$_key}": #{valueToJSON($_value)}'; | |
$is_first_value: false; | |
} | |
$json_string: $json_string + '}'; | |
} @else if(type-of($value) == 'list') { | |
$json_string: $json_string + '['; | |
@each $_value in $value { | |
@if not($is_first_value) { | |
$json_string: $json_string + ','; | |
} | |
$json_string: $json_string + '#{valueToJSON($_value)}'; | |
$is_first_value: false; | |
} | |
$json_string: $json_string + ']'; | |
} @else { | |
@if (type-of($value) == 'bool') { | |
$json_string: $value; | |
} @else { | |
$json_string: '"#{$value}"'; | |
} | |
} | |
@return $json_string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not suitable for production ;)