Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V1
V1
  • Getting started
    • Introduction
    • What is Specify?
    • Getting started
    • Glossary
  • Advanced Repository
    • Getting started
    • Figma Variables & Styles
    • Tokens Studio
    • CLI & Config
    • Querying a SDTF graph
    • GitHub
    • Parsers
      • to-css-custom-properties
      • to-style-dictionary
      • to-tailwind
      • to-sdtf
      • to-javascript
      • to-react-native
      • to-json
      • to-typescript
      • filter
      • select-modes
      • change-case
      • convert-color
      • convert-dimension
    • Templates
      • CSS Custom Properties
      • SDTF
      • Tailwind
    • REST API
    • Playground
  • Concepts
    • Token types
    • Configuration
    • Parsers
    • Templates
    • Best practices
  • Apps & Tools
    • Overview
    • GitHub
    • npm
    • GitLab
    • Bitbucket
    • Azure DevOps
    • REST API
    • CLI
    • Notion
    • Raycast
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
Powered by GitBook
On this page
  • Interface
  • Basic usage - JSON token values
  • Advanced usage - CSS token values

Was this helpful?

Edit on GitHub
Export as PDF
  1. Advanced Repository
  2. Parsers

to-json

This parser helps you pull design tokens in JSON with token values in JSON or CSS.

Interface

interface parser {
  name: 'to-json';
  output: {
    type: 'file';
    filePath: string;
  };
  options?: {
    output?: 'raw' | 'css';
  };
}

Basic usage - JSON token values

{
  "colors": {
    "$collection": {
      "$modes": [
        "light",
        "dark"
      ]
    },
    "Core": {
      "blue-100": {
        "$type": "color",
        "$value": {
          "dark": {
            "red": 229,
            "blue": 29,
            "alpha": 1,
            "green": 29,
            "model": "rgb"
          },
          "light": {
            "red": 255,
            "blue": 255,
            "alpha": 1,
            "green": 255,
            "model": "rgb"
          }
        },
        "$description": "token 1 aliased with n modes within collection within n groups"
      },
      "blue-700": {
        "$type": "color",
        "$value": {
          "dark": {
            "red": 229,
            "blue": 0,
            "alpha": 1,
            "green": 0,
            "model": "rgb"
          },
          "light": {
            "red": 255,
            "blue": 255,
            "alpha": 1,
            "green": 200,
            "model": "rgb"
          }
        },
        "$description": "token 2 aliased with n modes within collection within n groups"
      }
    },
    "semantic": {
      "background": {
        "button": {
          "primary": {
            "hover": {
              "$type": "color",
              "$value": {
                "dark": {
                  "$mode": "dark",
                  "$alias": "colors.Core.blue-100"
                },
                "light": {
                  "$mode": "light",
                  "$alias": "colors.Core.blue-700"
                }
              },
              "$description": "alias token with n modes within collection within n groups"
            }
          }
        }
      }
    }
  }
}
.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "To JSON",
      "parsers": [
        {
          "name": "to-json",
          "output": {
            "type": "file",
            "filePath": "tokens.json"
          }
        }
      ]
    }
  ]
}
tokens.json
{
  "colors": {
    "Core": {
      "blue-100": {
        "dark": {
          "model": "rgb",
          "red": 229,
          "green": 29,
          "blue": 29,
          "alpha": 1
        },
        "light": {
          "model": "rgb",
          "red": 255,
          "green": 255,
          "blue": 255,
          "alpha": 1
        }
      },
      "blue-700": {
        "dark": {
          "model": "rgb",
          "red": 229,
          "green": 0,
          "blue": 0,
          "alpha": 1
        },
        "light": {
          "model": "rgb",
          "red": 255,
          "green": 200,
          "blue": 255,
          "alpha": 1
        }
      }
    },
    "semantic": {
      "background": {
        "button": {
          "primary": {
            "hover": {
              "dark": {
                "model": "rgb",
                "red": 229,
                "green": 29,
                "blue": 29,
                "alpha": 1
              },
              "light": {
                "model": "rgb",
                "red": 255,
                "green": 200,
                "blue": 255,
                "alpha": 1
              }
            }
          }
        }
      }
    }
  }
}

Advanced usage - CSS token values

{
  "colors": {
    "$collection": {
      "$modes": [
        "light",
        "dark"
      ]
    },
    "Core": {
      "blue-100": {
        "$type": "color",
        "$value": {
          "dark": {
            "red": 229,
            "blue": 29,
            "alpha": 1,
            "green": 29,
            "model": "rgb"
          },
          "light": {
            "red": 255,
            "blue": 255,
            "alpha": 1,
            "green": 255,
            "model": "rgb"
          }
        },
        "$description": "token 1 aliased with n modes within collection within n groups"
      },
      "blue-700": {
        "$type": "color",
        "$value": {
          "dark": {
            "red": 229,
            "blue": 0,
            "alpha": 1,
            "green": 0,
            "model": "rgb"
          },
          "light": {
            "red": 255,
            "blue": 255,
            "alpha": 1,
            "green": 200,
            "model": "rgb"
          }
        },
        "$description": "token 2 aliased with n modes within collection within n groups"
      }
    },
    "semantic": {
      "background": {
        "button": {
          "primary": {
            "hover": {
              "$type": "color",
              "$value": {
                "dark": {
                  "$mode": "dark",
                  "$alias": "colors.Core.blue-100"
                },
                "light": {
                  "$mode": "light",
                  "$alias": "colors.Core.blue-700"
                }
              },
              "$description": "alias token with n modes within collection within n groups"
            }
          }
        }
      }
    }
  }
}
.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "To JSON",
      "parsers": [
        {
          "name": "to-json",
          "output": {
            "type": "file",
            "filePath": "tokens.json"
          },
          "options": {
            "output": "css"
          }
        }
      ]
    }
  ]
}
tokens.json
{
  "colors": {
    "Core": {
      "blue-100": {
        "dark": "rgb(229, 29, 29)",
        "light": "rgb(255, 255, 255)"
      },
      "blue-700": {
        "dark": "rgb(229, 0, 0)",
        "light": "rgb(255, 200, 255)"
      }
    },
    "semantic": {
      "background": {
        "button": {
          "primary": {
            "hover": {
              "dark": "rgb(229, 29, 29)",
              "light": "rgb(255, 200, 255)"
            }
          }
        }
      }
    }
  }
}
Previousto-react-nativeNextto-typescript

Last updated 1 year ago

Was this helpful?