Feat: Include simple arithmetic in JSON
See original GitHub issueAs a user when I have following JSON file:
{
"base": {
"value": 8
},
"spacing-unit": {
"magnitude": "3",
"value": "{base.value} * {spacing-unit.magnitude.value}"
}
}
I would like the result:
{
"base": {
"value: 8
},
"spacing-unit": {
"magnitude: "3"
"value: 24
}
}
Reading through CONTRIBUTING.md, it’s noted “Do not mutate property names or values in a format.”
Let me know if this feature is possible. Else, any chance of myself or the style-dictionary time including some sort of transformer, for this behaviour
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Arithmetic operations in JSON elements - IBM
Example Description Expression Result
Addition Basic addition /attr1 + /attr2 5
Subtraction Basic subtraction /attr1 ‑ /attr2 ‑3
Multiplication Basic multiplication /attr1 * /attr2 8
Read more >Working with JSON data in PowerShell - Scripting Blog
So there you have it, working with JSON data can be easy once you turn it into PowerShell objects. Hopefully this helps you...
Read more >Is it possible to do expressions/calculations in json?
No, it isn't possible to do math or any kind of expression in JSON as JSON is just a ...
Read more >Indexing, Querying, and Full-Text Search of JSON Documents ...
Let's look at another example, one where you have a large JSON, but only require a subpart of that document in your application....
Read more >The Book of Leaves: A Beautiful Stop Motion Film Featuring ...
If I didn't have the perfect shape, it meant I just had to collect more leaves. Above, you can see the result of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Perhaps consider using Javascript instead of JSON. It gives you some flexibility in your code rather than having to rely on
style-dictionary
to do the magic.For example:
You might run in to issues with brand/platform overrides, but this is the best I can suggest right now!
@danilovaz, your question references CSS custom properties.
Are those also tokens? Do you want the references maintained in your output?
It seems like what you want is this:
which, assuming those references are also tokens, should generate this token:
or with a
CSS-deep
format (does not come with style dictionary currently, but could be extended) you could get this token: