Connor Hinkson
Connor Hinkson

Reputation: 11

Export from Sketch App to JSON

I want to be able to export Layer Names and properties from Sketch to JSON format. I think I can figure out how to pull the info I need from Sketch, but I haven't started to code anything, because I haven't been able to find any info about this export issue.

I'm wondering if anyone can help confirm that Sketch can only export their supported formats or if export to JSON is possible. I don't want to dive into this project only to find out that I can't end up with a JSON file.

Upvotes: 1

Views: 4906

Answers (2)

oskarko
oskarko

Reputation: 4178

If you rename the .sketch extension file to .zip extension file you will see as many JSON files as pages your sketch document has inside a folder called "Pages". Also some BMP previews images and other JSON related to user and document information.

Upvotes: 0

Antonio Kaplan
Antonio Kaplan

Reputation: 11

I have been trying to work with this as well, and it turns out there are a few ways to get access to a JSON file in sketch.

  1. use the npm package sketch2json
  2. Turns out that if you unzip the .sketch file, there is a JSON file hiding inside.

    unzip sketch-header.sketch

This creates a folder called 'pages' with the .json file inside. To get the 'Layer Names', you can just read/serialize the .json file into a string, and then the path to collect the layer names is

const obj = JSON.parse(fileString);
object.layers.forEach((layer) => {
    console.log(layer.name);
});

Upvotes: 0

Related Questions