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

136
Views
Parsing a string into a format to be able to get data from JSON structure

So i was struggling to get my code to recognise this string sent from the front end of my site to the backend as a method to get some data from my JSON file. Please see the code below for clarification.

My NODE.JS Code:

function getData(filePath, cb){
    var str = '';
    fs.readFile(filePath, 'utf8', function(err, data){
      if(err) throw err;
      cb(data);
    });
  }


app.get("/api", (req, res)=>{

    var userID = req.query.userID

        getData('users.json', function(data) { 

            var processed = JSON.parse(data)
            
            processed = processed.userID
            console.log(processed)
     
           res.send(processed)
            console.log("completed request!")

        } );

})

My JSON File

{
    "RGdfei33":{
        "img":"https://upload.wikimedia.org/wikipedia/commons/7/7c/Broken_Castor_Rex_Rabbit.JPG",
        "bio":"I am a rex bunny",
        "name": "Koos Konijn"
    },
    "RGdfei3":{
        "img":"https://upload.wikimedia.org/wikipedia/commons/7/7c/Broken_Castor_Rex_Rabbit.JPG",
        "bio":"I am monkey",
        "name": ""
    },
    "FGdfei33":{
        "img":"https://upload.wikimedia.org/wikipedia/commons/7/7c/Broken_Castor_Rex_Rabbit.JPG",
        "bio":"I am a rex bunny",
        "name": "Koos Konijn"
    }}

Thanks Already!

about 4 years ago · Juan Pablo Isaza
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!