> they’ll end up parsing your comments too :( On the other hand: > JSON.parse(`{ "a": 1, "// comment": "done!", "b": 2 }`, (k, v) => k.startsWith('//') ? undefined : v) > { a: 1, b: 2 } Not anymore! (well, kinda)
-
-
Replying to @RReverser @mathias and
JSON.parse is already super expensive and you’re just adding to that by including comments in there and requiring the users to parse them and add additional logic to filter them out
2 replies 0 retweets 0 likes -
Replying to @bitandbang @RReverser and
JSON.parse expensive? Compared to what? +
@tverwaes2 replies 0 retweets 7 likes -
Replying to @mathias @RReverser and
Specifically bringing Node.js experience - JSON.parse() blocks the event loop which I'm sure you know isn't awesome. I assume (?) this behavior is different in the browser, though.
1 reply 0 retweets 0 likes -
Replying to @bitandbang @mathias and
I’d be surprised if it didn’t block in a browser
2 replies 0 retweets 1 like -
Replying to @b0neskull @bitandbang and
It does. There are however optimization opportunities for things like fetch(url).then(response => response.json()) where browsers could do a streaming parse off the main thread.
2 replies 0 retweets 5 likes -
Replying to @mathias @b0neskull and
Has there been any discussions on introducing `JSON.parseAsync()`?
3 replies 0 retweets 11 likes -
Replying to @sindresorhus @b0neskull and
It comes up from time to time, but no formal proposal yet.
2 replies 0 retweets 3 likes -
Replying to @mathias @sindresorhus and
new Response(text).json() (but currently this is slower than JSON.parse)
2 replies 0 retweets 12 likes -
Replying to @_developit @mathias and
That parses it off the main thread? Not just asynchronously? Cool! I assume it doesn't require copying the data an extra time, since presumably Response is written not to need to do that copy in the usual fetch case...
1 reply 0 retweets 1 like
Not saying it does in today’s browsers, but it’s a potential optimization.
-
-
-
Replying to @RReverser @mathias and
We're toying with it. It would only help if you're parsing 100s of KB of complicated JSON though. Does that happen frequently?
1 reply 0 retweets 2 likes - 4 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.