Skip to content

JavaScript · browsers and Node.js

"[object Object]" is not valid JSON

You get "[object Object]" is not valid JSON when you pass an object to JSON.parse(), which turns it into that text before parsing.

Updated · 2 min read

console
Chrome, Edge, Node.jsSyntaxError: "[object Object]" is not valid JSON
Node.js 18, older ChromeSyntaxError: Unexpected token o in JSON at position 1
FirefoxSyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
SafariSyntaxError: JSON Parse error: Unexpected identifier "object"

Find it in your JSON

Paste the text that failed. The checker points at the exact spot, and Repair fixes most syntax mistakes.

Input · JSON

Invalid JSON

Line 1, column 1

This is the text "[object Object]", not JSON.

1[object Object] ^

Fix: An object was turned into a string with String() or + "" instead of JSON.stringify(). Serialize it with JSON.stringify() first.

Why this happens
Invalid JSONRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

Why it happens

JSON.parse() converts anything that is not a string into one, and every plain object becomes the same 15 characters, [object Object]. The parser reads the [ as an array and fails at the o. The value was either parsed already or never serialized. Most common first:

1. Parsing data twice. res.json(), axios’s response.data, jQuery with dataType: 'json' and express.json() already return objects:

const res = await fetch('/api/preferences');
const prefs = await res.json();   // already an object
JSON.parse(prefs);                // SyntaxError: "[object Object]" is not valid JSON

2. Sending an object without JSON.stringify. fetch sends a plain-object body as the string [object Object]. The browser shows no error; your server does, when express.json() parses the request:

await fetch('/api/preferences', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: { theme: 'dark', fontSize: 14 },   // sent as "[object Object]"
});

3. Storing an object as text. localStorage.setItem('prefs', prefs), cookie values, URLSearchParams and template literals such as `${prefs}` all produce [object Object]. The error appears on the next read.

4. Low-code nodes. In n8n, fields from an HTTP Request node are already objects, so JSON.parse($json.body) in a Code node fails the same way.

How to fix “[object Object]” is not valid JSON

Parse once, where data enters your program. If a function can receive either form, check the type:

const prefs = typeof input === 'string' ? JSON.parse(input) : input;

fetch and axios

Delete the extra JSON.parse: await res.json() already parsed the body, and axios’s response.data is already an object.

Sending JSON

Serialize the body yourself with fetch:

await fetch('/api/preferences', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ theme: 'dark', fontSize: 14 }),
});

axios serializes plain objects for you, so axios.post('/api/preferences', { theme: 'dark' }) is already correct.

Express

After app.use(express.json()), req.body is the parsed object:

app.use(express.json());

app.post('/api/preferences', (req, res) => {
  const { theme, fontSize } = req.body;
  res.json({ saved: true, theme, fontSize });
});

If the server logs this error for one client’s requests, the bug is in that client (cause 2).

Storage, cookies and URLs

Write with JSON.stringify(prefs) and read with JSON.parse(...). For values already saved as [object Object], catch the error, remove the key and fall back to defaults. The JSON validator tells you whether a stored value is JSON or this text.

n8n

Use the field as it is, for example $json.body.theme, or write {{ JSON.stringify($json.body) }} where a text field needs JSON.

Same error in other languages

The rest of the family is in common JSON errors.

Questions

Why did older versions say position 1?

The parser accepted [ as the start of an array, then hit the o of object, the second character. Firefox reports the same spot as column 2.

Can I get my data back from "[object Object]"?

No. The conversion kept none of the keys or values. The Repair button turns the text into ["object Object"], which parses but holds nothing useful, so fix the code and save or send the data again.

Why does my page show [object Object] instead of the data?

Same conversion, different place: an object used where text was expected, as in el.textContent = user or alert(user). Show JSON.stringify(user, null, 2), or pick the fields you need.

Related errors

All common JSON errors

Esc