Skip to main content
Inspiring
March 22, 2023
Answered

faster JSON parsing: json2.js vs json3.js

  • March 22, 2023
  • 2 replies
  • 1747 views

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?

This topic has been closed for replies.
Correct answer sam272

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.

2 replies

sam272AuthorCorrect answer
Inspiring
March 24, 2023

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.

m1b
Community Expert
Community Expert
July 28, 2023

Hi @sam272, I only just saw this now. Good spotting!

m1b
Community Expert
Community Expert
March 22, 2023

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