Section 2 · Design Tokens
Token Pipelines: From JSON to Every Platform
20 min3 min readFill in the blanks
Lesson at a glance
Set up a token build pipeline that turns DTCG JSON into CSS custom properties per theme and native formats per platform, keeping references intact so runtime theming still works.
- 1What a pipeline does
- 2Keep the references
- 3A real pipeline with Style Dictionary
- 4Checks that run with the build
No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.
With tokens stored as DTCG JSON, something has to turn them into what each platform consumes: CSS custom properties for the web app and marketing site, Swift for the iOS driver app, Kotlin or XML for Android. That something is a token pipeline. It’s a small piece of code that every design system team ends up owning, and getting it right early saves months of drift later.
What a pipeline does
- Parse every source file and deep-merge them into one tree.
- Resolve aliases like
{color.blue.600}, rejecting broken or circular references. - Transform names and values for each platform:
color.action.bgbecomes--nw-color-action-bgin CSS andcolorActionBgin Swift;1rembecomes16points on iOS. - Format the result as a file: a block of custom properties, a Swift enum, an Android resource file.
Here’s the heart of the CSS side, small enough to read in one go:
const tokens = {
color: {
$type: 'color',
blue: { 600: { $value: { colorSpace: 'srgb', components: [0.122, 0.353, 0.878], hex: '#1f5ae0' } } },
white: { $value: { colorSpace: 'srgb', components: [1, 1, 1], hex: '#ffffff' } },
action: {
bg: { $value: '{color.blue.600}' },
text: { $value: '{color.white}' },
},
},
space: { $type: 'dimension', 4: { $value: { value: 1, unit: 'rem' } } },
};
// Walk the tree and collect every token with its path.
function flatten(node, path = [], type) {
const t = node.$type ?? type;
if ('$value' in node) return [{ path, type: t, value: node.$value }];
return Object.entries(node)
.filter(([key]) => !key.startsWith('