Skip to main content
Question

Get a less verbose format from API than raw JSON?

  • July 18, 2024
  • 0 replies
  • 1312 views

Hi,

I’m having big files on Figma and when dealing with them into Node.js I get:

Error: Cannot create a string longer than 0x1fffffe8 characters
    at TextDecoder.decode (node:internal/encoding:449:16)
    at utf8DecodeBytes (node:internal/deps/undici/undici:2973:34)
    at parseJSONFromBytes (node:internal/deps/undici/undici:4306:25)
    at successSteps (node:internal/deps/undici/undici:4288:27)
    at fullyReadBody (node:internal/deps/undici/undici:2724:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async consumeBody (node:internal/deps/undici/undici:4297:7)
    at getResponseBody (/xxxxxxxx/core/request.ts:217:13)
    at <anonymous> (/xxxxxxxx/core/request.ts:322:26) {
  code: 'ERR_STRING_TOO_LONG'
}

I know it’s not an issue with Figma because as a solution I could try to adjust my autogenerated client from the OpenAPI schema to deal with kind of “streams” to parse the JSON piece by piece but it complexifies the logic for just a few edge cases.

Note I did try to remove geometry: "paths" but the issue still exist.

Another solution would be to rely on the raw export of Figma, with “leaked” schema of Protocol Buffer but it sounds more like a workaround than relying on the official exposed schema.

I’m just curious if you have other ideas? Or a specific HTTP header to set another tinier format?

Thank you,

EDIT: about the Protocol Buffer schema, I could rely on GitHub - yagudaev/figma-to-json: 💾 Read/Write Figma Files as JSON but I’m not 100% sure it follows the exact same typings than the REST API… so it may break my whole analysis logic. Need to look at it deeper.

EDIT2: tomorrow I will give a try to parsing libraries that keep the whole content, it should work 👍

This topic has been closed for replies.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings