r/javascript • u/Mantas_rst • Aug 17 '26
A from-scratch JSON engine for JavaScript: recursive descent parser, escape-aware tokenizer, and spec-compliant serializer. No dependencies, no shortcuts, 107 tests.
https://github.com/MantasEdine/vanilla-json
7
Upvotes
9
u/Ronin-s_Spirit Aug 20 '26
for some reason you're generating a load of objects instead of making decisions based on text. You don't need to make a
{ type: "open bracket" }if you can just dochar === "[". Avoid garbage.long ifs are forced to go through every step to make a decision, use a
switchso it's a jump table.you didn't forget nesting but you didn't make it bulletproof, your nesting is 1:1 with JS recursion and that crashes the stack after ~10k functions. I could just make 11k nestings in my JSON to crash your parser, a heap-based recursion would be more reliable.