I am trying to convert a JSON in which some items can contains arrays as well. I get a very nicely structured table if I convert my JSON in json2table.com. I want similar table to be created in Excel using Javascript/nodejs. I tried some packages like ‘json2xls’, ‘xlsx’ etc. However I am not getting the desired output. Here’s my JSON.
JSON:
{
"name":"Gopi",
"id":"01",
"subjects":[{
"subject":"maths",
"marks":"84"
},
{
"subject":"science",
"marks":"85"
}],
"teachers":{
"name": "teacherA"
}
}
I am using below code. But I see [object Object],[object Object] under the column ‘subjects’
var json2xls = require('json2xls');
const fs = require('fs')
var json = {
"name": "Gopi",
"id": "01",
"subjects": [{
"subject": "maths",
"marks": "84"
},
{
"subject": "science",
"marks": "85"
}],
"teachers": {
"name": "teacherA"
}
}
var xls = json2xls(json);
fs.writeFileSync('stackof.xlsx', xls, 'binary');