Text Classifier not Working

i am using a text classifier to classify an gmail the text is stoed as “T” but the error is saying to use a parse
Failed to parse. Text: “[{“type”:“text”,“text”:“json\n{\"Customer Support\":true,\"Other\":false}\n”,“annotations”:}]”. Error: [ { “code”: “invalid_type”, “expected”: “object”, “received”: “array”, “path”: , “message”: “Expected object, received array” } ]

Hi @Faique_Usman

Your text classifier is expecting an object not an array.

Try this:

Step 1: Extract the text value

Add a Function or Set node before the Text Classifier.

If your field is T, extract the actual string:

Function node Js:

const raw = $json.T[0].text;

return [{ json: { parsedText: raw } }];

This removes the array and keeps only the text content.

Step 2: Parse the JSON string

Add another Function node (or combine with the first) in Js :

const raw = $json.parsedText.replace(/^json\s*/, ‘’).trim();

const parsed = JSON.parse(raw);

return [{ json: parsed }];

//Now your data becomes:

{

“Customer Support”: true,

“Other”: false

}

Step 3: Feed this into the Text Classifier

Configure the Text Classifier to use the entire JSON input (not a string field).

Now it matches the expected schema:

Object

Not array

Properly parsed