Unexpected Token u in JSON – Why JSON.parse Fails

Local only

Unexpected token u commonly means undefined reached JSON.parse. The parser sees the text undefined, which is a JavaScript value but not valid JSON.

Indent

9 chars · 1 line

Two-way sync · Edit either side and the other updates automatically.

Invalid JSONExpected a JSON value
Line 1Column 1Character 1Found “u”
undefined

JSON.parse runtime error

Why undefined produces Unexpected token u

Standard JSON has no undefined literal. If application code passes undefined into JSON.parse, the parser can receive the text undefined and fail immediately at the first u. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • Browser-local JSON processing
  • Route-specific malformed JSON example
  • Focused parser or repair guidance
  • Broken and corrected JSON example
  • Related JSON problem navigation

Steps

  1. Inspect the value immediately before JSON.parse and confirm whether it is undefined.
  2. Trace why the producer returned no value, especially storage keys and asynchronous code.
  3. Guard missing values explicitly instead of trying to make undefined valid JSON.

Undefined belongs to JavaScript, not JSON

JSON supports null, booleans, numbers, strings, arrays, and objects. JavaScript undefined is outside that grammar, so it must be handled by application logic before parsing or serialization.

  • A missing object property was read before parsing.
  • A storage lookup returned no saved value.
  • Asynchronous data was parsed before it arrived.

Choose a real fallback deliberately

If missing data is valid for the application, choose an explicit fallback such as null, an empty object, or an empty array based on the contract. Do not silently replace undefined without understanding the expected shape.

Unexpected token u example

The first value is a JavaScript literal, not JSON. A JSON null is valid syntax but only use it when null matches the application contract.

Invalid parser input

undefined

Valid JSON fallback example

null

Common questions

Frequently asked questions

Is undefined valid JSON?

No. JSON has null but does not define an undefined value.

Why does localStorage sometimes lead to this error?

Application code may transform a missing storage result into undefined before calling JSON.parse. Inspect the exact value rather than assuming stored JSON exists.

Can I replace undefined with null?

Only when null accurately represents the missing value in your data contract. Otherwise fix the producer or skip parsing until data exists.

Debugging a specific JSON issue? Browse JSON troubleshooting.