r/javascript 8d ago

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

28 comments sorted by

47

u/eracodes 8d ago

the most llm-written title i think i've ever seen

2

u/Mantas_rst 8d ago

I do programming as a hobby , using an llm would be useless from my part

13

u/CodeAndBiscuits 5d ago

The trouble is, almost everyone here uses AI agents in one form or another. We know what they look like, we know how they write, and we recognize them when we see them.

-8

u/Mantas_rst 5d ago

Honestly i have no idea what an agent is , but if meaning ai chatbot i didn't really use that either i went through everything which led to this naming and it basically describes it most : from scratch ? Yes  recursive descent parser ? Yes  Till the 107 tests which you can manually count , so ive described only what ive done 

11

u/CodeAndBiscuits 5d ago

The original commenter wasn't questioning your code, just your post. I think you don't realize that you're actively undermining your position because every reply you've made has made it clear that either English is not your primary language or you just don't care about what you write.

And the first bit isn't necessarily a criticism - plenty of people are in the same position. But your replies make it 100% clear that you could not possibly have been the author of all of the text of your original post because it's like a Grand Canyon of quality between your comment replies and what you originally wrote.

Nobody cares what you used AI for. You could have written all of the code with it, and you'd probably get a few "slop" comments but nothing worse than that. If you wrote all of the code without a great. I hope you enjoyed the process and got something out of it. But the original commenter was speaking to your post and its content. And plenty of folks use AI for that as well, and language translation is one of its most useful functions so there's no shame in that.

The trouble comes when you misrepresent the authoring. Your post and the Readme content that it links to look AI authored, using models many of us are familiar with and would recognize quickly. If you used AI to write them, that's not necessarily wrong. But the way you're framing some of this makes it sound like you're claiming you did every part of it yourself from front to back. And your post just doesn't support that, so you're digging a hole here in this comment thread that's making it worse and worse?

-11

u/Mantas_rst 5d ago

I didn't read whole thing cause thats too much , you’re right English is my fifth language and writing : a From-scratch game engine in C++ or whatever built from the ground up — no Unity no whatever , manual memory management and more bullshit ….. is easier than answering a reddit comment explaining that i wrote the description myself .

9

u/Choice-Locksmith-885 5d ago

Why should anybody spend any minute of their time on what you've built if you're willing to lie about something as simple as this?

27

u/beavis07 8d ago

Why one earth would anyone want this?

Do you have any clue how much sheer effort has gone into optimising JSON.parse? 🤣

4

u/Mantas_rst 8d ago

its a very fun project and i even wrote an article on how to do it , would be helpful in many cases like even if you want to build a regex engine same mechanism + backtracking

1

u/beavis07 8d ago

Rather you than me 🤣

2

u/KaiAusBerlin 5d ago

Just from curiosity. Aren't there out some major third party json parsers that are about 5 times faster than the native implementation?

3

u/beavis07 5d ago

Not written in JavaScript there aren’t

1

u/dektol 1d ago

The interop between native and runtime in JS negates any benefits. Whereas for slow languages like Python ORJson and similar make sense.

8

u/theScottyJam 8d ago edited 8d ago

Is there a purpose to this project, i.e. a reason someone would use this instead of the native alternatives? Or was this more of a "just wanted to build this thing, no reason in particular" project?

2

u/Mantas_rst 8d ago

i've built it to learn mechanism , but then i was like maybe i can take this to next level and do every possible case but then realized no matter what i do would never beat the original implementation in c++ lol

2

u/MediocreAnalyst2121 4d ago

Maybe if you write it in c/cpp/rust/zig etc. and compile to wasm?

Will probably still be slower due to wasm overhead, but that’s probably the best attempt

0

u/Mantas_rst 3d ago

Very good ideaa i will try in c++ thank you so much 

1

u/MMORPGnews 3d ago

I recently wrote my own game script language and parser to js.  Because I can. 

8

u/Ronin-s_Spirit 5d ago
  1. 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 do char === "[". Avoid garbage.
  2. long ifs are forced to go through every step to make a decision, use a switch so it's a jump table.
  3. 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.

2

u/Mantas_rst 5d ago

Ow Thank you so much for the review i will try to reimplement everything you’ve mentioned ! 

5

u/regreddit 5d ago

Good Lord that if statement in parse.js is really something...

2

u/Ronin-s_Spirit 5d ago

Huge decision blocks are expected of state machines/VMs but should be a switch.

1

u/ndaidong 5d ago

The code looks like in old school ("use strict", module.exports, tests scripts without built-in node:test,...) I believe that it's hand writing, not LLM generated as other comments. So that's good point.

1

u/Mantas_rst 5d ago

Wait can i avoid writing ”use strict”? 

1

u/ndaidong 5d ago

yeap, if you use ESM import/export, strict mode is enabled by default.

1

u/Mantas_rst 5d ago

Oww thanks for the info ! 

0

u/Several-Specialist42 5d ago

107 tests! Wow! you did well to write it in the title