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

215
Views
How do I get numbers of element from a JSON file with Typescript
  [
     {
       "dataset_id": "courses",
       "dept": "phys",
       "id": "301",
       "avg": 71.67,
       "instructor": "bryman, douglas",
       "title": "elec & magnetism",
       "pass": 146,
       "fail": 6,
       "audit": 0,
       "uuid": 441,
       "year": "2015"
     },
     {
       "dataset_id": "courses",
       "dept": "phys",
       "id": "301",
       "avg": 71.67,
       "instructor": "",
       "title": "elec & magnetism",
       "pass": 146,
       "fail": 6,
       "audit": 0,
       "uuid": 442,
       "year": "2015"
     },
     {
       "dataset_id": "courses",
       "dept": "phys",
       "id": "301",
       "avg": 73.07,
       "instructor": "louis-martinez, domingo",
       "title": "elec & magnetism",
       "pass": 113,
       "fail": 4,
       "audit": 0,
       "uuid": 5957,
       "year": "2013"
     }
   ]

Here is my JSON file and I intend to get a number of elements which is suppose to be 3. I tried to use:

    let num = JSON.parse(file).result.length;

I got a result of Syntax error says "Unexpected token c in JSON at position 0". What did I do wrong?

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

0

You'll need to provide a bit more context on how you're getting "file". Is it from an ajax request, is it a static file in your project directory, etc.?

However, since you're using typescript im wagering it is a static file (client or server side shouldnt matter).

You'll probably need to just export it correctly. Add export const variableName = [...] and then you should be able to import it in any file via import file from './filepath'. You shouldnt need to JSON.parse() it.

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!