Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'json/flat' format #138

Closed
dbanksdesign opened this issue Oct 1, 2018 · 4 comments
Closed

Add 'json/flat' format #138

dbanksdesign opened this issue Oct 1, 2018 · 4 comments

Comments

@dbanksdesign
Copy link
Member

From the discussion on #58 , we want to add different types of JSON formatting for different purposes. This format should output a JSON string that only has 1 level where the keys are the property name and the value is the property value. For example, this style dictionary JSON:

{
  "size": {
    "font": {
      "small": { "value": "13px" },
      "medium": { "value": "15px" },
      "large": { "value": "17px" },
      "base": { "value": "{size.font.medium.value}" }
    }
  }
}

Would output this in the 'json/flat' formatter:

{
  "SizeFontSmall": "13px",
  "SizeFontMedium": "15px",
  "SizeFontLarge": "17px",
  "SizeFontBase": "15px"
}

You can have a look at how the other formatters are written to see how to write a formatter and where it should go.

Make sure to include proper jsdoc comments and unit test!

@ericbreno
Copy link

Looking into it, interesting!

@chazzmoney
Copy link
Collaborator

Merged, closing

@kerryj89
Copy link

kerryj89 commented Oct 27, 2024

When using json/flat it keeps the hyphens and I'm assuming other symbols. Is there a way to easily transform it to not include them and into camelCase so that we can simply import the json and do tokens.sizeFontSmall and not tokens['size-font-small']?

@jorenbroekema
Copy link
Collaborator

Yes, by adding a name transform that converts token names to camelCase

E.g.

{
  "source": [
    "tokens.json"
  ],
  "platforms": {
    "json": {
      "transforms": [
        "name/camel"
      ],
      "buildPath": "build/json/",
      "files": [
        {
          "destination": "vars.json",
          "format": "json/flat"
        }
      ]
    }
  }
}

Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants