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

227
Visualizações
How to retrieve data from json file

I am having trouble with accessing my json file from my javascript file. I would like to change the object to a different text in my json file once a submit button is clicked on the webpage. I am aware that I would use ajax to achieve this goal, but I do not know how to access the json file.

This is the db.json file

{
{
  "assets": [
    {
      
      "id": "0946",
      "manufacturer": "SONY",
    },
    {
      "id": "0949",
      "manufacturer": "AUDIOTECNIA"
      
    }
],
  "transfers": [
    {
      "id": 1,
      "status": "in-progress"
    }
               ]
}

This is my Javascript file

 $('form').on('submit', function(e){
        e.preventDefault();

        parsedData = JSON.parse(db.json);
        console.log(parsedData[0].id)


    //Changing Status 

    $.ajax({ 
        type: "PATCH",
        url: `http://localhost:3000/transfers/`
        
        
    });

I've tried using parseData because I read that is how to retrieve the object, from the json file, but I do not believe I am writing it correctly. What documentation or steps would one recommend for solving this issue?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You have an extra comma after "in-progress",

const parsedData = JSON.parse(`{ 
   "transfers": [ { 
      "id": 1,      
      "status": "in-progress"
   }]
}`)

Then, to access id in parsedData:

console.log(parsedData.transfers[0].id)
over 4 years ago · Santiago Trujillo Relatório

0

You did not initialize the variable parsedData.

    var parsedData = JSON.parse(db.json);
over 4 years ago · Santiago Trujillo 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