News for hackers. Stuff that matters.
Re:The cost of parsing JSON by michaelmcmillan on Wednesday September 18, 2019 @11:31AM (#21006430)
So I guess we should "transpile" static objects into strings that we call with JSON.parse?

Not sure if I should end this comment with a /s or not.

Re:The cost of parsing JSON by fenwick67 on Wednesday September 18, 2019 @12:07PM (#21006807)
Sometimes you can have massive static objects. Like a list of emojis and their codepoints.[1] It could be useful in cases like that. You'd have to experiment, though.

[1] https://raw.githubusercontent.com/joypixels/emoji-toolkit/ma...

Re:The cost of parsing JSON by eloff on Wednesday September 18, 2019 @12:00PM (#21006737)
Since we compile JavaScript to an unreadable mess anyway... Why not?
Re:The cost of parsing JSON by alxhill on Wednesday September 18, 2019 @11:50AM (#21006615)
That's...what the article proposes, so yes?
Re:The cost of parsing JSON by alufers on Wednesday September 18, 2019 @12:09PM (#21006824)
The key part here is

> As long as the JSON string is only evaluated once the JSON.parse approach is much faster.

So doing this would only work on top-level declarations, because the javascript runtime will cache the parsed JSON structure for subsequent executions (eg. creating an object in a loop).

Re:The cost of parsing JSON by nostrademons on Wednesday September 18, 2019 @01:12PM (#21007525)
WebPack, properly configured, will let you import plain old .json files through the normal es6 import mechanism. It doesn't use this technique though: the JSON file is treated as normal JS source (preprocessed to remove unnecessary quotes etc.) and wrapped with an export.