community-group
community-group copied to clipboard
The $ property name prefix should be unnecessary with a well-structured schema
I was looking into this format recently and I came away quite confused why the $
prefix was required everywhere. The rationale pointed to in the format spec (https://design-tokens.github.io/community-group/format/#additional-group-properties) indicates that it's to differentiate between group properties and the tokens within a group.
How this is usually handled in JSON is that the key/value maps are separated from the data structurally - they don't mix in a single object. For groups, all the child tokens would be in a sub-object called children
or tokens
, and so could never clash with group properties like description
.
So a group would look like:
{
"Group of tokens": {
"description": "This is an example of a group containing a nested group",
"tokens": {
"Subgroup of tokens": {
"Token 1 name": {
"value": "#aabbcc"
},
"Token 2 name": {
"value": "#ddeeff"
}
}
}
}
}
Many, many JSON schemas have both defined properties and open-ended key/value maps and work just fine without prefixing every defined property name in the schema. This spec is the first I've ever seen that does it, and I think it harms the human readability of the documents. It also makes programatic handling of groups more difficult, because to get child tokens you need to filter on a group name prefix instead of just getting the keys of the children
property.