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

403
Views
How can I extract data from a JSON file using javascript?

I have this simple variable which I am trying to extract data from. I've parsed it successfully to a json object and tried to print a value based on it a key. But all it says is "undefined". This example I provided is actually a snippet of the json I am trying to manipulate. The full file is actually a json object where one of the elements contains an array of many json objects (these are the ones I ultimately have to access). I have watched countless tutorials and have followed them exactly, but none seem to have this issue.

const x = `{
        "status": "ok",
        "userTier": "developer",
        "total": 2314500,
        "startIndex": 1,
        "pageSize": 10,
        "currentPage": 1,
        "pages": 231450,
        "orderBy": "newest"
            }`;

JSON.parse(x);
console.log(x.status);

Can anybody suggest something I may be doing wrong? Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

JSON.parse Return value The Object, Array, string, number, boolean, or null value corresponding to the given JSON text. - MDN

You have to assign the parsed result to some variable/constant from where you can use later that parsed value and then use that variable to extract data as:

const x = `{
        "status": "ok",
        "userTier": "developer",
        "total": 2314500,
        "startIndex": 1,
        "pageSize": 10,
        "currentPage": 1,
        "pages": 231450,
        "orderBy": "newest"
            }`;

const parsedData = JSON.parse(x);
console.log(parsedData.status);

or you can directly get value one time after parsed as:

const x = `{
        "status": "ok",
        "userTier": "developer",
        "total": 2314500,
        "startIndex": 1,
        "pageSize": 10,
        "currentPage": 1,
        "pages": 231450,
        "orderBy": "newest"
            }`;

console.log(JSON.parse(x).status);

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