Answer the question
In order to leave comments, you need to log in
Parsing JSON data to JS, how faster?
I receive json data from a websocket, parse it and set a condition, can I use some plugins or other additives to make this process faster (I mean speed up data parsing), or is native functions the fastest thing that can be?
In fact, as I understand it, the native ones should be the fastest, because. they do according to the 1st condition, the rest of the plugins will do several actions
Answer the question
In order to leave comments, you need to log in
const json = `{
"type": "widget-chart",
"title": "Handcrafted Wooden Sausages",
"data": {
"chart": {
"height": "100%",
"type": "donut"
},
"series": [
44,
55,
41,
17,
15
],
"responsive": [
{
"breakpoint": 480,
"options": {
"chart": {
"width": 200
},
"legend": {
"position": "bottom"
}
}
}
]
},
"_id": "5cf6307a245e2b001efd2111",
"id": "5cf6307a245e2b001efd2111"
}
`
console.time('eval')
let e = {}
eval('e = ' + json)
console.timeEnd('eval')
console.time('JSON.parse')
let p = {}
p = JSON.parse(json)
console.timeEnd('JSON.parse')
console.time('Function')
let f = {}
f = new Function('return ' + json)
console.timeEnd('Function')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question