Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
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 answers
Answer question

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 Report

0

You did not initialize the variable parsedData.

    var parsedData = JSON.parse(db.json);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!