From 2dbaefb86e82669ea2f9dcf2f5dd698a2aed50dd Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 13 Nov 2025 00:49:11 +0000 Subject: [PATCH] Enhance JSON DocumentLoader: Update label and description for 'Separate by JSON Object' option, and add type check for JSON objects in array processing. --- .../nodes/documentloaders/Json/Json.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/components/nodes/documentloaders/Json/Json.ts b/packages/components/nodes/documentloaders/Json/Json.ts index 694fc26ab..042c81ef8 100644 --- a/packages/components/nodes/documentloaders/Json/Json.ts +++ b/packages/components/nodes/documentloaders/Json/Json.ts @@ -67,10 +67,10 @@ class Json_DocumentLoaders implements INode { optional: true }, { - label: 'Separate by JSON Object', + label: 'Separate by JSON Object (JSON Array)', name: 'separateByObject', type: 'boolean', - description: 'If enabled and the JSON file contains an array, each object in the array will become a chunk', + description: 'If enabled and the file is a JSON Array, each JSON object will be extracted as a chunk', optional: true, additionalParams: true }, @@ -343,12 +343,14 @@ class JSONLoader extends TextLoader { for (const item of jsonArray) { if (this.separateByObject) { - const metadata = this.extractMetadata(item) - const pageContent = this.formatObjectAsKeyValue(item) - documents.push({ - pageContent, - metadata - }) + if (typeof item === 'object' && item !== null && !Array.isArray(item)) { + const metadata = this.extractMetadata(item) + const pageContent = this.formatObjectAsKeyValue(item) + documents.push({ + pageContent, + metadata + }) + } } else { const content = this.extractContent(item) const metadata = this.extractMetadata(item)