1

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.

  • Im diving into that myself. Did you explore further? – Chris Slowik Mar 03 '17 at 23:44
  • No I have been busy with other projects. That was a side project that I just haven't had the time to touch again yet. – Connor Hinkson Mar 06 '17 at 16:04
  • Looks like i'm able to export JSON. Sketchtool also exports JSON from the command line but it's way too verbose - more info than I need (or want to parse). Gonna keep working on it, but like you it's a side project so I'll tinker where I can. Will post up any revelations. – Chris Slowik Mar 07 '17 at 14:38
  • I'm interested in this project. Have you done something about it? – Matteo Vacca Jun 08 '17 at 22:00

2 Answers2

0

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);
});
0

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.

oskarko
  • 3,382
  • 1
  • 26
  • 26