diff --git a/lib/JSON2CSVParser.js b/lib/JSON2CSVParser.js index e8eae7e9..e4e25062 100644 --- a/lib/JSON2CSVParser.js +++ b/lib/JSON2CSVParser.js @@ -40,7 +40,7 @@ class JSON2CSVParser extends JSON2CSVBase { preprocessData(data) { const processedData = Array.isArray(data) ? data : [data]; - if (processedData.length === 0 || typeof processedData[0] !== 'object') { + if (!this.opts.fields && processedData.length === 0 || typeof processedData[0] !== 'object') { throw new Error('Data should not be empty or the "fields" option should be included'); } @@ -63,4 +63,4 @@ class JSON2CSVParser extends JSON2CSVBase { } } -module.exports = JSON2CSVParser; \ No newline at end of file +module.exports = JSON2CSVParser;