</>
ValidateHTML

Invalid Value Type in JSON

JSON supports exactly six value types: strings (double-quoted), numbers, booleans (true/false), null, objects, and arrays. Values like undefined, NaN, Infinity, functions, dates, and regex are not valid JSON. These values exist in JavaScript but have no JSON representation.

Why It Matters

The JSON parser rejects the document immediately. This commonly happens when using JSON.stringify() on JavaScript objects that contain undefined values, Date objects, or functions.

Common Causes

  • Serializing a JavaScript object that holds undefined, NaN, Infinity, a function, or a Date by hand instead of through JSON.stringify.
  • Writing booleans or null with the wrong casing, such as True, False, or None copied from Python.
  • Leaving a bare value like a Date or a regex literal in the data, which has no JSON equivalent.

Code Examples

Invalid JSON
{
  "name": "John",
  "age": NaN,
  "salary": Infinity,
  "callback": undefined,
  "active": True
}
Valid JSON
{
  "name": "John",
  "age": null,
  "salary": 999999,
  "callback": null,
  "active": true
}

How to Fix

  • 1Replace undefined with null or remove the property entirely.
  • 2Replace NaN and Infinity with null or a sentinel number value.
  • 3Use lowercase true, false, and null. JSON is case-sensitive: True, False, and None are invalid.
  • 4Convert Date objects to ISO strings before serializing: new Date().toISOString().

Frequently Asked Questions

What value types does JSON actually support?
Exactly six per RFC 8259: string, number, boolean (true or false), null, object, and array. Anything outside this set, including undefined, NaN, Infinity, dates, and functions, is not valid JSON.
How does JSON.stringify handle undefined and functions?
In an object it drops keys whose value is undefined or a function entirely. In an array it converts them to null. NaN and Infinity also become null. This silent conversion can lose data, so check the output.
How should I store a date in JSON?
There is no date type in JSON. Store it as a string, usually ISO 8601 like "2026-06-17T10:00:00Z", and parse it back into a date object in your code after reading the JSON.

Check Your JSON Now

Our JSON validator detects this error automatically and shows the exact line and column.

Open JSON Validator
Recommended

Cloudways · Managed Cloud Hosting

Fix this JSON error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).

Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303

Start free trial

Related JSON Errors

View all JSON errors