0

I am using the xlsx module in node.js. But apparently the xlsx.utils.sheet_to_json returns JSON that is not double quoted; It's either single quoted or not quoted at all. The returned JSON looks like this:

[
  {
    student_Id: 1,
    phone_number: 87654321,
    f_name: 'Barns',
    l_name: 'Illinois',
    address: 'Denmark kurkum mohao street 88 bldg. 29',
  },
  { student_Id: 3, f_name: 'Charlie' }
]

In order to extract the Key attributes (Student_id, phone_number...) i need to use the Object.keys method, which only works if the data is double quoted. So is there a way that my outputted data will be double quoted? like this:

[
  {
    "student_Id": 1,
    "phone_number": 87654321,
    "f_name": "Barns",
    "l_name": "Illinois",
    "address": "Denmark kurkum mohao street 88 bldg. 29",
  }
]

Even if it nivolves using a different method/module.

b_a9f
  • 9
  • 2

1 Answers1

0

Try to put your result in JSON.stringify(your result), so you will get double quoted result.

JSON.stringify({
 student_Id: 1,
 phone_number: 87654321,
 f_name: 'Barns',
 l_name: 'Illinois',
 address: 'Denmark kurkum mohao street 88 bldg. 29',
})
Mini elephant
  • 13
  • 1
  • 2