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:
parent
e3ee0b4f88
commit
2dbaefb86e
|
|
@ -67,10 +67,10 @@ class Json_DocumentLoaders implements INode {
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Separate by JSON Object',
|
label: 'Separate by JSON Object (JSON Array)',
|
||||||
name: 'separateByObject',
|
name: 'separateByObject',
|
||||||
type: 'boolean',
|
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,
|
optional: true,
|
||||||
additionalParams: true
|
additionalParams: true
|
||||||
},
|
},
|
||||||
|
|
@ -343,12 +343,14 @@ class JSONLoader extends TextLoader {
|
||||||
|
|
||||||
for (const item of jsonArray) {
|
for (const item of jsonArray) {
|
||||||
if (this.separateByObject) {
|
if (this.separateByObject) {
|
||||||
|
if (typeof item === 'object' && item !== null && !Array.isArray(item)) {
|
||||||
const metadata = this.extractMetadata(item)
|
const metadata = this.extractMetadata(item)
|
||||||
const pageContent = this.formatObjectAsKeyValue(item)
|
const pageContent = this.formatObjectAsKeyValue(item)
|
||||||
documents.push({
|
documents.push({
|
||||||
pageContent,
|
pageContent,
|
||||||
metadata
|
metadata
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const content = this.extractContent(item)
|
const content = this.extractContent(item)
|
||||||
const metadata = this.extractMetadata(item)
|
const metadata = this.extractMetadata(item)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue