Skip to content

Commit c5b0fdf

Browse files
committed
Added condition to check for situations where there are no document schemas
1 parent 883471f commit c5b0fdf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/json2csv.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
3535
* list of field names.
3636
*/
3737
function processSchemas(documentSchemas: string[][]) {
38+
// If there are no document schemas then there is nothing to diff and no unqiue fields to get
39+
if (documentSchemas.length === 0) {
40+
return [];
41+
}
42+
3843
// If the user wants to check for the same schema (regardless of schema ordering)
3944
if (options.checkSchemaDifferences) {
4045
return checkSchemaDifferences(documentSchemas);
@@ -53,8 +58,8 @@ export const Json2Csv = function(options: FullJson2CsvOptions) {
5358
function checkSchemaDifferences(documentSchemas: string[][]) {
5459
// have multiple documents - ensure only one schema (regardless of field ordering)
5560
const firstDocSchema = documentSchemas[0],
56-
restOfDocumentSchemas = documentSchemas.slice(1),
57-
schemaDifferences = computeNumberOfSchemaDifferences(firstDocSchema, restOfDocumentSchemas);
61+
restOfDocumentSchemas = documentSchemas.slice(1),
62+
schemaDifferences = computeNumberOfSchemaDifferences(firstDocSchema, restOfDocumentSchemas);
5863

5964
// If there are schema inconsistencies, throw a schema not the same error
6065
if (schemaDifferences) {

0 commit comments

Comments
 (0)