res.json() vs JSON.parse(res.text())

Benchmark created on


Description

Quick perf test to compare const data = res.json() to the splitted const text = res.text(); const data = JSON.parse(text)

Setup

const products = '{"products":[{"Name":"Cheese","Price":2.5,"Location":"Refrigerated foods"},{"Name":"Crisps","Price":3,"Location":"the Snack isle"},{"Name":"Pizza","Price":4,"Location":"Refrigerated foods"},{"Name":"Chocolate","Price":1.5,"Location":"the Snack isle"},{"Name":"Self-raising flour","Price":1.5,"Location":"Home baking"},{"Name":"Ground almonds","Price":3,"Location":"Home baking"}]}'

Test runner

Ready to run.

Testing in
TestOps/sec
res.json()
const myRequest = new Request(products);

fetch(myRequest)
  .then((response) => response.json())
  .then((data) => console.log(data))
ready
JSON.parse(res.text())
const myRequest = new Request(products);

fetch(myRequest)
  .then(async (response) => JSON.parse(await response.text()))
  .then((data) => console.log(data))
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.