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

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

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 Denunciar

0

You did not initialize the variable parsedData.

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