Found myself scrolling through the Google Chrome Developers Channel on youtube. Found myself a cool video about Faster apps with JSON.parse.
Let me summarize the video for you if you don’t have enough time to watch it!
JSON.parse('…')
is much faster to parse, compile, and execute compared to an equivalent JavaScript literal — not just in V8 (1.7× as fast), but in all major JavaScript engines.
Example:
const data = {foo: 42, bar:1337, …}
the equivalent but faster:
const data = JSON.parse('{"foo": 42, "bar": 1337, ...}')
Tooling
Use Tooling to help you automatically transform object literals to json.parse as a build time optimization. Webpack implements this change in v4.35.3.
If you’d like to know the details you can watch the video, they do a great way of explaining it!
Happy programming!