FlowiseAI/Flowise · error · Error
Expected string, at position ${i} got ${typeof pageContent}
Error message
Expected string, at position ${i} got ${typeof pageContent} What it means
Thrown by JSONTextLoader.load (Json.ts) during a type check on each parsed document: the loader expects every parsed pageContent to be a string. It fires when the JSON pointer resolves a field whose value is a number, boolean, array, object, or null rather than text.
Source
Thrown at packages/components/nodes/documentloaders/Json/Json.ts:286
return [{ pageContent: raw, metadata: {} }]
}
public async load(): Promise<Document[]> {
let text: string
let metadata: Record<string, string>
if (typeof this.filePathOrBlob === 'string') {
const { readFile } = await TextLoader.imports()
text = await readFile(this.filePathOrBlob, 'utf8')
metadata = { source: this.filePathOrBlob }
} else {
text = await this.filePathOrBlob.text()
metadata = { source: 'blob', blobType: this.filePathOrBlob.type }
}
const parsed = await this.parse(text)
parsed.forEach((parsedData, i) => {
const { pageContent } = parsedData
if (typeof pageContent !== 'string') {
throw new Error(`Expected string, at position ${i} got ${typeof pageContent}`)
}
})
return parsed.map((parsedData, i) => {
const { pageContent, metadata: additionalMetadata } = parsedData
return new Document({
pageContent,
metadata:
parsed.length === 1
? { ...metadata, ...additionalMetadata }
: {
...metadata,
line: i + 1,
...additionalMetadata
}
})
})
}
View on GitHub (pinned to abe4a8601a)
Solutions
- Inspect the JSON at the failing index i — the field the pointer targets is not a string.
- Point the pointer at a string-valued field (e.g. '/body' or '/description') instead of '/id' or '/count'.
- If you want non-string scalars as text, coerce them in a pre-processing step or pick a pointer to a string field.
- If records are heterogeneous, filter or normalize the JSON before loading.
Example fix
// before: pointer '/price' resolves to a number
new JSONLoader(file, '/price')
// after: point at a text field, or stringify scalars
new JSONLoader(file, '/description')
// or coerce in the source data:
// data.forEach(r => { r.text = String(r.price) }) Defensive patterns
Strategy: type-guard
Validate before calling
// Walk the JSON at the pointer and ensure every resolution is a string
function pointerValuesAreStrings(json, pointer) {
const records = Array.isArray(json) ? json : [json]
return records.every((rec, i) => {
const v = pointer ? require('jsonpointer').get(rec, pointer) : rec.text
return typeof v === 'string'
})
} Type guard
function isStringPageContent(parsed) {
return parsed.every((p, i) => typeof p.pageContent === 'string')
} Try / catch
try {
return await jsonLoader.load()
} catch (e) {
if (/Expected string, at position (\d+) got (\w+)/.test(e.message)) {
const [, idx, type] = e.message.match(/position (\d+) got (\w+)/)
throw new Error(`JSON field at record ${idx} is ${type}, not a string — fix the pointer`, { cause: e })
}
throw e
} Prevention
- Point the JSON pointer at a guaranteed string field.
- Pre-scan the JSON to confirm the target field is always a string.
- Normalize non-string scalars to strings upstream.
- For mixed schemas, filter or coerce records before loading.
When it happens
Trigger: A JSON pointer like '/price' resolves to a numeric field; '/tags' resolves to an array; the pointer is empty so the whole record becomes pageContent (an object); the source JSON has null where a string was expected.
Common situations: User points the loader at a numeric/boolean JSON field by mistake; a JSONL feed mixes schemas where some records have a string 'text' and others have an object; the pointer is omitted for a JSON array of non-string scalars.
Related errors
- Expected string, at position ${i} got ${typeof pageContent}
- Invalid JSON in the Chat NVIDIA NIM's baseOptions: ${excepti
- Invalid JSON in the ChatOpenAI's BaseOptions: ${exception}
- Invalid JSON in the ChatOpenAI's BaseOptions: ${exception}
- Invalid JSON in the ChatOpenRouter's BaseOptions: ${exceptio
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/bf3047b0cc4b0ff2.
Report an issue: GitHub.