Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the complexity of JSON.parse() in JavaScript?

The title says it all. I'm going to be parsing a very large JSON string and was curious what the complexity of this built in method was.

I would hope that it's θ(n) where n is the number of characters in the string since it can determine whether there is a syntax error or not.

I tried searching but couldn't come up with anything.

like image 753
thed0ctor Avatar asked Nov 03 '14 05:11

thed0ctor


1 Answers

JSON is very simple grammar that does not require even lookaheads. As soon as GC is not involved then it is purely O(n).

like image 54
c-smile Avatar answered Sep 25 '22 22:09

c-smile