Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda