How to parse JSON object to CSV file using json2csv nodejs module

前端 未结 6 822
青春惊慌失措
青春惊慌失措 2020-12-10 07:44

I\'m currently learning how to parse a JSON object to a CSV file using the json2csv node module. Have never worked with JSON before, so this is all new to me.

My JSO

6条回答
  •  无人及你
    2020-12-10 08:17

    const { Parser } = require('json2csv');
    
    let myCars = {
        "car":
        {
            "name": ["Audi"],
            "price": ["40000"],
            "color": ["blue"]
        }
    };
    
    let fields = ["car.name", "car.price", "car.color"];
    
    const parser = new Parser({
        fields,
        unwind: ["car.name", "car.price", "car.color"]
    });
    
    const csv = parser.parse(myCars);
    
    console.log('output',csv);
    

    will output to console

提交回复
热议问题