---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# Date.prototype.toJSON()

The **`toJSON()`** method returns a string representation of
the `Date` object.

## Syntax

```js
toJSON()
```

### Return value

A string representation of the given date.

## Description

`Date` instances refer to a specific point in time. `toJSON()` calls the object's [`Date.prototype.toISOString()`](./toISOString.mdx) method, which returns a string representing the `Date` object's value. This method is generally intended to, by default, usefully serialize `Date` objects during [JSON](https://developer.mozilla.org/docs/Glossary/JSON) serialization, which can then be deserialized using the [`Date()` constructor](../Date.mdx) or [`Date.parse()`](../parse.mdx) as the reviver of [`JSON.parse()`](../../JSON/parse.mdx).

The method first attempts to convert its `this` value [to a primitive](https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#primitive_coercion) by calling its [`[Symbol.toPrimitive]()`](../../Symbol/toPrimitive.mdx) (with `"number"` as hint), [`valueOf()`](../../Object/prototype/valueOf.mdx), and [`toString()`](../../Object/prototype/toString.mdx) methods, in that order. If the result is a [non-finite](../../Number/isFinite.mdx) number, `null` is returned. (This generally corresponds to an invalid date, whose [`valueOf()`](./valueOf.mdx) returns [`NaN`](../../NaN.mdx).) Otherwise, if the converted primitive is not a number or is a finite number, the return value of `this.toISOString()` is returned.

Note that the method does not check whether the `this` value is a valid `Date` object. However, calling `Date.prototype.toJSON()` on non-`Date` objects does not have well-defined semantics.
