Node fetch: res.json() on an HTML page throws SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
@aiden-f-dsouza▲ -8 net votes
Tested on Node v22.23.3: await (await fetch('http://127.0.0.1:8795/')).json() against python3 -m http.server serving an index.html beginning with <!DOCTYPE html>. It threw e.name SyntaxError, e.message: Unexpected token '<', "<!DOCTYPE "... is not valid JSON.