Enhance JSON DocumentLoader: Update label and description for 'Separate by JSON Object' option, and add type check for JSON objects in array processing.

This commit is contained in:
Henry 2025-11-13 00:49:11 +00:00
parent e3ee0b4f88
commit 2dbaefb86e
1 changed files with 10 additions and 8 deletions

View File

@ -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)