-4

i have the following json :

{
  "student": [{
    "cert_id": "59826ffeaa6-b986fc04d9de",
    "batch_id": "b3d68a-402a-b205-6888934d9",
    "name": "Alice",
    "program_name": "Computer Science",
    "register": "Fffffffffff",
    "grades": {
      "smester1": {
        "course": [{
          "course_title": "Data Structures",
          "course_code": "CC02",
          "credit": "4",
          "int_grade": "B",
          "ext_grade": "C",
          "grade_point": "2.01",
          "letter_grade": "C",
          "credit_point": "8.05",
          "date_of_exam": "11/2015"
        }, {
          "course_title": "Computation",
          "course_code": "CC03",
          "credit": "4",
          "int_grade": "B",
          "ext_grade": "C",
          "grade_point": "1.93",
          "letter_grade": "C",
          "credit_point": "7.71",
          "date_of_exam": "11/2016"
        }]
      },
      "smester2": {
        "course": [{
          "course_title": "Design of Algorithm",
          "course_code": "CS02",
          "credit": "4",
          "int_grade": "A",
          "ext_grade": "A",
          "grade_point": "4",
          "letter_grade": "C",
          "credit_point": "9.64",
          "date_of_exam": "11/2016"
        }, {
          "course_title": "Operating system concept",
          "course_code": "CC03",
          "credit": "4",
          "int_grade": "c",
          "ext_grade": "C",
          "grade_point": "1.00",
          "letter_grade": "C",
          "credit_point": "6.71",
          "date_of_exam": "11/2016"
        }]
      }
    }
  }]
}

i want to take data of grades in nodejs...help me

adiga
  • 34,372
  • 9
  • 61
  • 83
  • 2
    What have you tried? Show your best attempt so far to solve this problem and explain what went wrong (errors, unexpected results, etc.) Also "take data of grades" is rather vague. Please show what the expected output will be. – p.s.w.g Feb 06 '19 at 06:58
  • if i put above json file in my html....the nodejs is reading the entire file but i can get access to grades, hich contains all smester deatils. [ { cert_id: '59826ffe-7cac-45da-ba6-b986fc04d9de', batch_id: 'b3dbc571-168a-402a-b205-66a8888934d9', name: 'Alice', program_name: 'MSc Computer Science', register: 'Ffffffffffff', grades: { smester1: [Object], smester2: [Object] } } ] – Blockchain Expert Feb 06 '19 at 07:02

1 Answers1

0

If you want access to grades, just do student[0].grades:

fs.readFile("student.json", (err, data) => {
    if (err) throw err;
    console.log(data.student[0].grades);
});
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79