Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Reading json file on javascript return error

I'm trying to read a big json file with JS

const jsonFile = JSON.parse("3BP-OOP-PFR.json");
console.log(jsonFile);

The problem is

VM334:1 Uncaught SyntaxError: Unexpected token B in JSON at position 1 at JSON.parse () at main.js:1:23

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are parsing the filename as JSON, which will fail. The JSON.parse function expects a JSON string value to parse, not a file.

Have you tried importing the file instead?

import jsonFile from "3BP-OOP-PFR.json";

console.log(jsonFile);

If you are using a browser, you will need to fetch the file:

fetch('https://website.com/subdir/3BP-OOP-PFR.json')
  .then(res => res.json())
  .then(json => console.log(json))

If you want to use async/await:

const res = await fetch('https://website.com/subdir/3BP-OOP-PFR.json')
const json = await res.json();
console.log(json);

Keep-in-mind that if you are fetching a JSON file locally, this will fail. Make sure you are using a webserver and running off of localhost. I believe there are flags that you can pass (CLI) to the browser to override the local file loading error.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!