I have a JSON file containing the following:
{
"colors": [
{
"name": "red",
"hex": "#c33"
},
{
"name": "blue",
"hex": "#2f2"
},
{
"name": "green",
"hex": "#22f"
}
]
}
The JSON needs to be in an array [] as I'm also using the same JSON for creating Handlebars templates and Handlebars seems to require the JSON to be like this(unless there's a way to get Handlebars to do otherwise?).
I'm using sass-json-vars to import the JSON file into my SASS :
@import 'variables.json';
Then what I want to do is loop through the JSON to create a list of SASS variables based on the values and names in the JSON.
So far the closest I can get is something like this:
@each $id, $val in $colors {
@each $idB, $valB in $val {
body {
color: $idB;
}
}
}
This is giving me both key and value:
body {
color: #22f;
}
body {
color: hex;
}
Which is obviously no good.
I can't find a way to use dot notation or something similar to reference the value matching a key and nesting loops like the above doesn't seem to work.
The kind of output in SASS i'm after is:
$red : #c33;
$blue : #2f2;
... etc
Can anyone help?