Parse a Json(with array and objects) and export the data into Excel file in Node.js

后端 未结 2 1243
长情又很酷
长情又很酷 2021-02-08 15:30

I am new to Node.js. My requirement is, I need to parse a JSON and export the data into Excel file with all the fields in the JSON.

My JSON is as follows:



        
2条回答
  •  爱一瞬间的悲伤
    2021-02-08 15:39

    You are using the json2xls module which accepts either on object or an array, but nested level object structure. What I mean is that your definition would be fine if introduction and objectives were scalar properties. I.e.

    {
        "id": 1255,
        "title": "...)",
        "description": "...",
        "keyTerms": "...",
        "visible": true,
        "introduction": "string/int/float/bool/date",
        "objectives": "string/int/float/bool/date"
    }
    

    or

    [
    {
        "id": 1255,
        "title": "...)",
        "description": "...",
        "keyTerms": "...",
        "visible": true,
        "introduction": "string/int/float/bool/date",
        "objectives": "string/int/float/bool/date"
    },
    {
        "id": 1256,
        "title": "...)",
        "description": "...",
        "keyTerms": "...",
        "visible": true,
        "introduction": "string/int/float/bool/date",
        "objectives": "string/int/float/bool/date"
    }
    ]
    

    but in your case introduction is an object with nested elements, and objectives is an array of objects, which both are interpreted as [object] [object]

    I do not know what you want in your excel file, but you need to decide how to flatten the structure first.

提交回复
热议问题