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

433
Visualizações
Why the JSON.parse returning [Object Object] instead of value?

here is my json:

[
    {
        "customer": "BigCo",
        "performances": [
            {
                "playID": "hamlet",
                "audience": 55
            },
            {
                "playID": "as-like",
                "audience": 35
            },
            {
                "playID": "othello",
                "audience": 40
            }
        ]
    }
]

here is my code(environment is node.js):

let readFile = require('fs').readFileSync

let invoices = JSON.parse(readFile('./invoices.json', 'utf8'))

console.log(invoices);

here is my result:

[
  { customer: 'BigCo', performances: [ [Object], [Object], [Object] ] }
]

I have read some questions related, and get some solutions like invoices = invoices[0] or JSON.parse(JSON.stringify()). The thing I really hope to know is the reason. Why do I get the result [ [Object], [Object], [Object] ] and Which part cause the problem?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I am no expert but the reason for this is that they are nested objects.

about 4 years ago · Juan Pablo Isaza Relatório

0

You need to first convert the contents of the file into string and then parse it to JSON.

Use the following code :

let readFile = require('fs').readFileSync

let invoices = JSON.parse(readFile('./invoices.json', 'utf8').toString())

console.log(invoices[0]);

the output would be :

{
  customer: 'BigCo',
  performances: [
    { playID: 'hamlet', audience: 55 },
    { playID: 'as-like', audience: 35 },
    { playID: 'othello', audience: 40 }
  ]
}
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