n8n JSON Parameter Needs to Be Valid JSON: Fix the Body
Fix n8n's HTTP Request JSON parameter error without damaging your data. Reproduce eight edge cases, choose the right body mode, preserve types, and validate dynamic or AI-generated values before sending requests.

- 1Return an object for the complete JSON body instead of inserting unescaped text into a quoted template
- 2Verify both JSON validity and exact values with eight cases covering quotes, backslashes, newlines, tabs, Unicode, and HTML
- 3Preserve data types, validate the failing item, and check previous successful actions before replaying production writes
The most useful first fix for n8n's "JSON parameter needs to be valid JSON" error is to stop inserting unescaped text inside a handwritten JSON string. In the HTTP Request node, use Body Content Type: JSON, Specify Body: Using JSON, then make the entire body an expression that returns an object. n8n can serialize that object without turning a customer's quotation marks or line breaks into broken JSON syntax.
That fix addresses body construction, not every API failure. An unavailable input field, invalid expression, wrong data type, or rejected API schema still needs its own correction. Start with the quick fix, then use the diagnostic table if the error remains.
This guide includes an eight-case dataset, exact expressions, expected results, and offline checks against the real n8n-workflow expression engine. The examples use fictional data, not customer records. Documentation and source behavior were checked on November 1, 2026; older n8n releases can display the slightly different message "JSON parameter need to be an valid JSON."
Quick Fix: Return an Object From the Entire Body
For this example, your incoming item must contain a string named message. If your data uses text, content, or a nested path, substitute that actual field. A copied expression cannot create a missing input value.
- Open the failing HTTP Request node and inspect its Input data.
- Keep the method and URL required by your API. Turn Send Body on.
- Set Body Content Type to JSON.
- Set Specify Body to Using JSON.
- Change the complete JSON body field to Expression and replace its contents with the expression below. Keep one outer expression around the object; do not put quotation marks around the entire block.
- Inspect the resolved result for the failing item before executing against a test endpoint you control.
Object Body for a Message
{{ { message: $json.message } }}
The outer {{ ... }} belongs to n8n's expression syntax. The inner { ... } creates a JavaScript object. The result should be an object with a message field, not a string containing literal {{ characters and not a manually escaped JSON document.
This is the same whole-object approach recommended in n8n's HTTP Request troubleshooting documentation. It is particularly useful for text containing quotation marks, newlines, HTML, or backslashes.
Only test with an endpoint and data you are authorized to use. Disconnect email, payment, publishing, and other write actions while debugging. Correcting a JSON error is not a reason to replay a production workflow indiscriminately.
Identify Which Part Is Actually Failing
A request passes through several different checks: resolve the expressions, construct the body, send the request, and interpret the response. Similar-looking messages can belong to different stages.
| What you see | What it points to | What to inspect next |
|---|---|---|
JSON parameter needs to be valid JSON in an HTTP Request parameter | n8n cannot parse a resolved JSON parameter | The resolved body, headers, or query parameter field named in the error |
invalid syntax in an expression | The expression itself is malformed | Parentheses, braces, operators, and the expression mode |
A missing field or undefined result | The selected input does not contain the expected value | The failing item's actual JSON path and upstream output |
Can't determine which item to use | An upstream item reference is ambiguous or unlinked | Item relationships, not escaping |
An actual HTTP 400 or 422 response | The receiving service rejected the request | Its response details, required fields, types, and business rules |
Invalid JSON in response body | The returned content could not be parsed as JSON | Response Format, response content type, and the actual response body |
An input parsing error occurs before that particular request can be sent successfully. It does not prove that earlier items or upstream nodes did nothing. Check execution history before retrying a workflow that writes data.
The HTTP Request node also supports Using JSON for headers and query parameters. If your body is correct, inspect those fields too. Conversely, changing Response Format does not fix malformed outgoing JSON: it controls how n8n handles incoming response data.
For item-reference errors, use our separate n8n item-linking guide. Replacing .item with .first() can select the wrong customer while appearing to fix the workflow.
Why Valid-Looking JSON Breaks After an Expression Resolves
There are three things that can look similar in the editor:
- An object: a structured value with fields, arrays, numbers, and booleans.
- JSON text: a string describing a value using JSON's syntax.
- A template: text containing expressions that have not yet been replaced by their results.
A JSON validator can approve a template without proving that its final result is valid. Consider the following pattern.
Fragile Quoted Interpolation
{ "message": "{{ $json.message }}" }
The braces and expression characters are inside a JSON string, so the template itself can pass a syntax check. With message equal to Plain text, the resolved JSON is also valid.
But if the message is Use the "Pro" plan, ordinary interpolation inserts those inner quotation marks into the surrounding JSON string. They now act as syntax instead of message content. A literal newline inside the inserted string can also break parsing; some unescaped backslash sequences can even produce valid JSON with the wrong value.
Do not solve this by deleting punctuation from the customer's message. Build an object or serialize the value correctly. Quotes, accents, and line breaks are legitimate content, not inherently bad data.
The JSON standard requires escaping quotation marks, reverse solidus characters, and control characters inside strings. Line breaks used to indent a JSON document are different from unescaped line breaks inside one of its string values.

Reproduce the Problem With Eight Fictional Inputs
Make a separate test workflow with Manual Trigger, a Code node, and a disconnected or safely configured HTTP Request node. Set the Code node to Run Once for All Items and paste this dataset. The labels let you inspect individual records without sending anything externally.
Create the Test Inputs
const cases = [
{ label: "plain", message: "Plain text" },
{ label: "quotes", message: 'Use the "Pro" plan.' },
{ label: "newline", message: "First line\nSecond line" },
{ label: "backslash", message: "Keep C:\\temp\\notes.txt unchanged." },
{ label: "tab", message: "Column A\tColumn B" },
{ label: "unicode", message: "Caf\u00e9 \u2014 ready \u2713" },
{ label: "empty", message: "" },
{ label: "html", message: '<a href="https://example.com">Open</a>' }
];
return cases.map((entry) => ({ json: entry }));
Compare the resolved value from Fragile Quoted Interpolation with Object Body for a Message. For string results, use a JSON parser, then compare the parsed message with the original. A green validation result is insufficient if a backslash was interpreted as an escape and changed the content.
| Input label | Fragile template outcome | Object-body outcome |
|---|---|---|
plain | Parses and preserves the text | Preserves the text |
quotes | Invalid JSON | Preserves the quotation marks |
newline | Invalid JSON | Preserves the line break |
backslash | Parses, but \t and \n change the value | Preserves the literal path |
tab | Invalid JSON | Preserves the tab |
unicode | Parses and preserves these characters | Preserves the characters |
empty | Parses and preserves the empty string | Preserves the empty string |
html | Invalid JSON because of the attribute quotes | Preserves the original HTML string |
These are expression-and-serialization results, not claims that every receiving API accepts every message. An API may reject an empty string or disallow HTML even though the body is valid JSON.
Choose the Body Mode That Matches Your API
n8n's HTTP Request reference documents several body formats. Choose based on the API contract, not on which option makes an error disappear.
| Body configuration | Appropriate use | Main pitfall |
|---|---|---|
| JSON + Using Fields Below | A small set of named fields | Confirm the evaluated value types; imported cURL fields may be strings |
| JSON + Using JSON + one object expression | Nested objects, arrays, or several typed dynamic values | The complete field must evaluate to the intended object |
| JSON + Using JSON + a text template | An existing template you deliberately maintain | Each dynamic value needs correct serialization |
Raw + application/json | An API integration deliberately requiring raw JSON text | Serialize the complete body once; setting a header does not serialize it |
| Form-Data or Form URLencoded | Endpoints documented to accept those formats | This is not equivalent to sending a JSON body |
Using Fields Below avoids building punctuation around ordinary field values. Enter a name such as message, then set that value to the expression {{ $json.message }}. For nested data and deliberate numbers or booleans, the object-expression approach makes the payload shape easier to review.
Do not assume importing a working cURL command preserves all data types. n8n documents that cURL import brings parameter values in as strings; it recommends switching to Using JSON when numbers and booleans need to retain their types. Keep credentials in n8n's credential system, not in shared screenshots or example bodies.
Use JSON.stringify Without Adding Another Pair of Quotes
Sometimes you need to maintain a JSON text template. In that case, serialize the value at the point where it becomes JSON text. JSON.stringify() supplies its own surrounding quotes for a string and escapes its contents.
Safe Serialized Value in a Template
{ "message": {{ JSON.stringify($json.message) }} }
This template is not ordinary JSON before n8n evaluates it. Validate the resolved text, not the unevaluated expression. With a real string input, the serialized value can safely contain quotes, tabs, line breaks, and backslashes.
Equivalent n8n String Helper
{ "message": {{ $json.message.toJsonString() }} }
n8n documents toJsonString() as escaping a string and wrapping it in quotes, like JSON.stringify(). Use it only after confirming the field is a string. Calling a string method on a missing value is a different failure.
Incorrect Extra Quotes Around a Serialized Value
{ "message": "{{ JSON.stringify($json.message) }}" }
Do not use that last pattern. The serializer already returns a quoted JSON string, so the additional template quotes can produce malformed JSON. Adding JSON.stringify() everywhere is not a universal repair: its location and the type expected at that location matter.
Missing data is another reason serialization is not enough. MDN's JSON.stringify() reference explains that serializing undefined does not produce a normal JSON value. Validate required inputs instead of hoping the serializer invents them.
Preserve Arrays, Booleans, Numbers, and Null
A valid request can still be wrong. These values have different meanings:
| Intended value | Different value to avoid | Why it matters |
|---|---|---|
false | "false" | A boolean flag became a string |
0 | "0" | A count became a string |
["billing", "review"] | "[\"billing\",\"review\"]" | An array became serialized text |
{ "id": "00123" } | "[object Object]" | An object became a display string |
null | "null" | An explicit null became a four-character string |
"00123" | 123 | A textual identifier lost leading zeros |
Typed Object Body
{{ {
message: $json.message,
active: $json.active,
count: $json.count,
tags: $json.tags,
customer: $json.customer,
note: $json.note ?? null
} }}
This preserves the values' existing types. It does not turn the string "false" into the boolean false, or a JSON-looking string into an array. Inspect incoming data first, then perform explicit conversions only when the API's contract requires them.
For example, Boolean("false") evaluates to true in JavaScript because the string is nonempty. A blind conversion can silently invert a business flag. Similarly, converting an identifier to a number may destroy significant leading zeros. These are data-contract errors, not missing-commas errors.
Expected Typed Payload
{
"message": "Use the \"Pro\" plan.\nKeep C:\\temp\\notes.txt unchanged.",
"active": false,
"count": 0,
"tags": ["billing", "review"],
"customer": { "id": "00123" },
"note": null
}
null, an empty string, and a missing property are not interchangeable. In an object, a property containing undefined is normally omitted during JSON serialization; a property containing null remains present. Only use the ?? null fallback when the receiving API allows null. For a required field, reject or route the item instead.
The nullish fallback also preserves false, 0, and "". Replacing it with || changes the behavior for those values, so choose based on meaning rather than convenience.
Handle JSON Text From AI Nodes Without Guessing
First inspect what the upstream node actually returned. It may be a structured object, a string containing JSON, or ordinary text with a Markdown code fence. Those require different handling.
If the value is already an object, pass the object. If it is a string and you genuinely need the object it describes, parse it. Do not apply JSON.parse() to every value, and do not remove quotation marks globally: that destroys valid string contents.
Parse and Validate a Message Payload
Put this in a Code node set to Run Once for Each Item. For this specific example, the upstream field is payload, and the receiving contract requires a nonempty message string. Rename the input field to match your real data.
const raw = $json.payload;
let payload;
if (typeof raw === "string") {
try {
payload = JSON.parse(raw);
} catch {
throw new Error("payload must contain valid JSON text");
}
} else {
payload = raw;
}
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
throw new Error("payload must be a JSON object");
}
if (typeof payload.message !== "string" || payload.message.trim() === "") {
throw new Error("payload.message must be a nonempty string");
}
return { json: { message: payload.message } };
The code deliberately returns only the field this example needs. Extend the validation and returned fields to match your API. It is not a general schema validator, and it intentionally rejects an array or a fenced Markdown answer rather than trying to repair unknown content.
If the AI node supports a structured response, prefer requesting and validating that structure upstream. n8n's Structured Output Parser can enforce a declared shape; when generating a schema from a JSON example, n8n treats every example field as mandatory. A schema still does not prove that generated facts are correct.
After parsing and validation, the HTTP Request body can use the earlier Object Body for a Message expression. Inspect this Code node's output: the old payload wrapper is no longer part of the returned shape.
When an API Really Wants JSON Inside a String Field
Some APIs deliberately require a field to contain serialized JSON text. In that case, making the outer body an object and serializing that one inner value is correct. It is not the same as accidentally converting every nested object into a string.
Deliberately Serialized Nested Value
{{ { value: JSON.stringify($json.customer) } }}
For the fictional customer { "id": "00123" }, the outer body's value field is a string containing {"id":"00123"}. The outer serializer escapes that string correctly during transport. Use this pattern only when the API documentation requires a string; otherwise pass $json.customer directly as an object.
A community report about a JSON string nested in an HTTP body also shows why to inspect stray surrounding quotes and a literal leading equals sign. Removing a local parser error can reveal a separate service-side validation error. That is progress, but not proof the request is correct yet.
Use Raw JSON Only Deliberately
If you intentionally choose Raw with Content Type: application/json, provide JSON text. Serialize the complete object once.
Serialized Raw Body
{{ JSON.stringify({ message: $json.message, active: $json.active }) }}
Do not paste a normal object into a field that expects text and rely on a display such as [object Object]. Equally, do not serialize a JSON string again unless the API genuinely expects a string at the top level. Double serialization can turn an intended object into a quoted string containing an object representation.
Setting Content-Type: application/json labels the body; it does not repair malformed content or convert a JavaScript object to JSON text by itself. Raw mode can move an error from n8n's local validation to the remote service instead of fixing it.
There is an important nuance: serializing the whole object is not automatically wrong in Using JSON, because n8n can parse JSON text there. It is usually unnecessary when the complete expression can return the object directly. Review the resolved type, body mode, and final payload together.
Diagnose Item 0, Item 1, or a Later Failure
[item 0] identifies the first input item to that node. [item 7] identifies the eighth. These are item indexes, not line numbers in the JSON document and not necessarily the original source's row numbers after filtering or sorting.
Open the failed execution, select the reported input item, and inspect the fields used by the expression. Look for a quote, real newline, missing nested object, unexpected type, or a different output shape. Compare it with a successful item rather than repeatedly checking only the first preview.
In one n8n community discussion, the author initially thought JSON.stringify() was ineffective, then found the problem was a later item. Another item 7 report illustrates the same diagnostic distinction. These are historical user reports, not evidence of a universal current n8n bug.
Use pinned or mocked data to reproduce the problematic value without repeating upstream requests. Pinning is a development aid and is not used for production executions, so verify the real input shape before returning the workflow to service.
After the fix, test the first item, the failed item, and every case in the eight-input dataset. Check execution history and your API's idempotency or deduplication options before replaying successful writes. Do not enable retries as a cure for a deterministic formatting error.
Check Static Syntax and Exported Expressions Separately
For genuinely static JSON, check double-quoted property names and strings, commas between fields, matching brackets, and the absence of comments or trailing commas. JSON is not JavaScript object-literal syntax. True, undefined, and single-quoted keys are not valid JSON values or delimiters.
MDN's JSON parsing reference explains these syntax failures. You can inspect a fictional or redacted resolved payload in ByteVerse's JSON formatter, but do not paste secrets or real customer content into public validators or support threads. A syntactically valid document still needs to match the API schema.
Workflow exports introduce another layer. n8n stores an expression-valued parameter as a string with a leading =, while the expression editor presents the {{ ... }} syntax. An exported node configuration and a standalone request body are different documents.
Expression Inside a Workflow Export
{
"jsonBody": "={{ { message: $json.message } }}"
}
That is an illustrative parameter fragment, not a complete importable workflow and not the JSON to send to your API. Do not copy its jsonBody wrapper into the body editor or let its storage-marker equals sign become part of a literal business field. Also avoid copying Markdown fences into the JSON parameter.
If you are still learning the canvas, the n8n beginner guide explains input items and node execution. If a trigger never delivers data to the node, use the webhook troubleshooting guide; body escaping cannot fix an unregistered webhook.
Final Checklist Before Reconnecting Production
- Confirm which parameter failed: body, headers, or query parameters.
- Inspect the exact input item named in the error and resolve every field path against it.
- Choose a body format supported by the receiving API.
- Prefer one object expression for structured JSON, or serialize text at the correct boundary.
- Compare parsed values as well as parse success, especially backslashes, nulls, booleans, arrays, and identifiers.
- Validate required fields, reject unexpected types, and retain only the data the API needs.
- Test with fictional edge cases and an endpoint you control before reconnecting writes.
- Inspect prior successful actions before retrying, and retain a redacted example plus node and n8n versions for support.
The goal is not merely to remove the red error banner. It is to send the intended structured value for the correct item, without silently changing its contents.
How the Examples Were Checked
The accompanying automated checks execute the article's expressions using n8n-workflow 2.16.0 on Node.js 24.12.0, with synthetic input objects. They exercise quoted interpolation, whole-object expressions, JSON.stringify(), toJsonString(), nested values, missing fields, and the exact validation code shown above. Network access is disabled during those checks.
The HTTP Request source snapshot reviewed for this guide distinguishes structured body values from text requiring JSON parsing. That supports the object-versus-template explanation, but a source snapshot is not a promise that every older node version has identical behavior.
This is not a live n8n Cloud, task-runner, HTTP transport, or external API test. The expression package version is not a certification of your installed n8n application. UI configuration and API requirements are based on the linked documentation; verify your node version and service contract in your own test workflow.
Frequently Asked Questions
Why does n8n say JSON parameter needs to be valid JSON when a validator accepts it?
A validator may be checking the template rather than the text produced by the expression. A quote, newline, or missing field can make the resolved result invalid. Inspect the exact failing item and return an object for the full body, or serialize each dynamic value correctly when constructing JSON text.
What does item 0 mean in the n8n JSON error?
Item 0 is the first input item to the failing node, not the first line of the JSON body. Item 7 is the eighth input item. Inspect that record because a later item can contain different punctuation, missing fields, or unexpected types even when earlier items succeed.
Should I use JSON.stringify or toJsonString in n8n?
Use either to serialize a string when inserting it into JSON text, without another pair of surrounding quotes. For a complete body expression returning an object, serialization of each ordinary field is unnecessary. Missing data still needs validation, and a deliberately serialized nested string should match the receiving API's requirements.
Can changing Content Type or Response Format fix this error?
Choose the body content type required by the API, but a header cannot make malformed JSON valid. Response Format controls incoming data and does not fix the outgoing body. An actual HTTP 400 or 422 response requires checking the service's response and schema rather than repeatedly changing quote escaping.
Why does the workflow pass a manual test but fail later?
A manual preview may use a different item or pinned development data. Production data can contain quotes, line breaks, nulls, or a different field structure. Test the reported failed item and representative edge cases. Check earlier successful actions before retrying a workflow that sends messages or writes records.
Sources and Further Reading
- n8n: HTTP Request common issues
- n8n: HTTP Request body formats, response options, and cURL import
- n8n: Expressions versus data nodes
- n8n: String transformation functions
- n8n: Structured Output Parser
- n8n: Pin and mock data
- MDN: JSON.stringify
- MDN: JSON.parse
- RFC 8259: The JSON Data Interchange Format
- Cover photograph: cottonbro studio / Pexels.
- Photography: olia danilevich / Pexels, used under the Pexels license. The photograph is illustrative and does not depict the tested workflow.
Share this article
Written by
Ali RehmanAuthor at ByteVerse
A Full Stack Developer and Tech Writer specializing in React.js, Next.js, and modern JavaScript, sharing insights on web development, frontend technologies, backend APIs, and scalable applications.
View all posts

