Cibles
DTCG JSON
Import and export tokens as DTCG 2025.10 JSON, with a semantic round trip and no silent loss.
DSF tokens have the semantics of the DTCG Format, Color and Resolver Modules 2025.10. JSON and
.dsf are two serializations of the same token graph: JSON appears only when you import or
export it.
Export
dsfc tokens export fixtures/scenarios/01-button-calculated --output tokens/
tokens/
├── calculated-button.resolver.json # DTCG Resolver Module document
├── foundation.tokens.json # one file per token_source
├── light.tokens.json
└── dark.tokens.json
{
"color": {
"$type": "color",
"surface": {
"$value": {
"colorSpace": "srgb",
"components": [1, 1, 1],
"hex": "#ffffff"
}
}
}
}
The same export is the dtcg target of dsf.hcl and of
dsfc build --target dtcg.
Strict and materialized
Export is strict by default: a value DTCG cannot represent fails with DSF-K013 instead
of being dropped. Calculated token values are such values:
tokens.dsf:323:5: error DSF-K013: token `button.height` cannot be exported to DTCG: computed value `token.button.padding-block * 2 + token.font.line-height.base300 + token.stroke-width.thin * 2` is not representable in strict export; export it as its value with a loss report (`dsfc tokens export --materialize`, or `materialize = true` on the dtcg target)
Materialized export is explicit: dsfc tokens export --materialize, or
options = { materialize = true } on the dtcg target.
dsfc tokens export examples/fluent --output tokens/ --materialize
info DSF-K014: materialized export: 3 computed value(s) written as literals; see fluent-2-example.loss.json
- The resolver structure is kept: sets, modifiers, contexts and files.
- Each computed value is replaced, in the file that declares it, by its resolved value.
If that value would differ between the permutations where the file is active, the export
fails with
DSF-K013rather than pick one. - Every replacement is listed in
<package>.loss.json:
{
"format": "dsf-dtcg-loss-report",
"version": "0.1",
"entries": [
{
"token": "type.body",
"file": "global.tokens.json",
"pointer": "#/type/body/$value",
"kind": "computed-value-materialized",
"detail": "token.font.line-height.base300 / token.font.size.base300",
"source": { "file": "tokens.dsf", "line": 260, "column": 26 }
}
]
}
Resolving the exported JSON gives exactly the package’s tokens; this is tested on both
example ports. Physical pixels (px(…)) and angles are still rejected.
Import
dsfc tokens import brand.resolver.json --output tokens.dsf
Import accepts a .tokens.json or a .resolver.json document. Files referenced by a resolver
must stay inside --root (the file’s directory by default), and remote references are never
fetched (DSF-K019).
Resolve
dsfc tokens resolve fixtures/scenarios/01-button-calculated --input theme=dark
Prints the resolved tokens of one resolver input as JSON. Modifiers you do not set use their default.
Mapping
| DTCG | DSF |
|---|---|
{ "value": 16, "unit": "px" } |
dp(16) |
{ "value": 1, "unit": "rem" } |
rem(1) |
"{color.surface}" (alias) |
token.color.surface |
fontFamily, letterSpacing (camelCase members) |
font_family, letter_spacing (snake_case) |
$description, $deprecated, $extensions |
description, deprecated, extensions |
Resolver sets, modifiers, resolutionOrder |
set, modifier, resolution_order |
The round trip DTCG → DSF → DTCG preserves token paths, types, values, references (form and
target), groups, descriptions, deprecation, extension data and resolver behavior. It does
not preserve whitespace, key order or number spelling (1.0 and 1).
cargo test runs a 120-fixture DTCG conformance corpus. The full mapping is in
spec/companion/dtcg-interop.md.