Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda