Copy link to clipboard
Copied
So I've been looking for a faster way to parse large JSON files in Illustrator scripting and I think I may have found a solution if anyone else is ever looking for this:
Instead of the standard json2.js (https://github.com/douglascrockford/JSON-js) I came across json3.js (https://github.com/bestiejs/json3) as a drop-in replacement.
In my use case (5mb+ JSON files), JSON.parse() is ~60x faster (5 seconds vs 5 mins) - seems to just be a more modern and faster implementation.
Only issue I've seen so far is a bit of funkiness with how it handles escaped non-Ascii characters.
Anybody else have experience with these libraries or know of any issues that might come up switching from json2 to json3?
1 Correct answer
update for the "escaped non-Ascii characters" issue mentioned above:
line 642 in json3.js needs extra () to evaluate properly in Illustrator script for some reason or it will error on certain escaped characters (/u00ed for instance). I made a fork of json3 with this change if anyone needs it: https://github.com/sam272/json3forillustrator/blob/c98707a15a3d88f393749c6678ffbc43f89f4d53/lib/json3.js#L642
Will update with any other issues I find.
Explore related tutorials & articles
Copy link to clipboard
Copied
HI @sam272, I've been using json3.js since forever, because if I recall correctly, it handled recursive references better. I honestly didn't know it was faster. I can say that it has performed well for me. - Mark
Copy link to clipboard
Copied
update for the "escaped non-Ascii characters" issue mentioned above:
line 642 in json3.js needs extra () to evaluate properly in Illustrator script for some reason or it will error on certain escaped characters (/u00ed for instance). I made a fork of json3 with this change if anyone needs it: https://github.com/sam272/json3forillustrator/blob/c98707a15a3d88f393749c6678ffbc43f89f4d53/lib/json...
Will update with any other issues I find.
Copy link to clipboard
Copied
Hi @sam272, I only just saw this now. Good spotting!

