Hi everyone
,
I’m working on an automation in n8n where I generate email content using the OpenAI Message a Model node (O1 model). The AI returns a JSON string containing both subject and body, like this:
{
“subject”: “Welcome to Workshop – Performance Marketing Services”,
“body”: “Dear Jacob,\n\nThank you for joining our workshop…”
}
However, the model output comes inside a single text string located in:
json.content[0].text
(or in some versions under json.output_text)
So both the subject and body arrive together as raw JSON text, not as separate fields. When I try to access them directly, the value shows undefined.
My Goal
I want to extract:
subject → for email subject input
body → for email message input
…as separate values inside the next node (e.g., Send Email, WhatsApp, Google Sheets, etc.)
Solution
Because the model returns a JSON string, we need to parse it using expressions.
EXPRESSION FOR SUBJECT
{{ JSON.parse($node[“Message a model”].json.content[0].text).subject }}
EXPRESSION FOR BODY
{{ JSON.parse($node[“Message a model”].json.content[0].text).body }}
If your output is under json.output_text instead (depending on version), then use:
{{ JSON.parse($node[“Message a model”].json.output_text).subject }}
{{ JSON.parse($node[“Message a model”].json.output_text).body }}
Tip
Make sure the node name inside $node[“Message a model”] matches your exact node name — including spaces and capitalization.
Example OpenAI Output Structure
type: “message”
status: “completed”
content:
content[0]:
type: “output_text”
text: “{\n "subject": "…", \n "body": "…" }”
Request
Is there a simpler or more recommended way to structure output from the O1 model so n8n receives separate fields directly?
Any guidance or best practices would be appreciated ![]()
Thanks in advance!
You can activate “Require specific Output Format” within your AI Agent or LLM Chain Node and add an “Structured Output Parser” to your Agents.
I have tried it also it wasn’t working
If you share your workflow here (use the code function), I can have a look at it and maybe will be able to help you. The workflow snippet I have posted works very consistent with the output.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.