How date is stored in JSON
Normal JSON (JavaScript Object Notation) does not have a built-in or native data type for dates or times.
Because the JSON standard only defines six basic types (string, number, object, array, boolean, and null), dates must be represented using one of these existing types.
In practice, dates are almost universally stored as a string or a number.
1. Primary Method: ISO 8601 String 📅
The most common, recommended, and interoperable way to store a date in JSON is as an ISO 8601 formatted string.
This format is language-agnostic, human-readable, and unambiguous because it explicitly includes time zone information (or indicates UTC).
| Format Type | Example | Description |
|---|---|---|
| Date-Time | "2025-09-30T17:52:51.000Z" | The most complete form, including the date, time, and the "Z" (Zulu/UTC) time zone indicator. |
| Date Only | "2025-09-30" | For fields that only require the calendar date. |
| Offset | "2025-09-30T17:52:51+01:00" | Includes a time zone offset from UTC. |
Why ISO 8601 is Recommended:
- Interoperability: It is the widely accepted international standard, making it easy for different programming languages (Python, Java, C#, etc.) and systems to correctly parse and interpret the same date.
- Time Zone Aware: It prevents common errors by allowing you to explicitly specify the time zone (ideally UTC using the
Zsuffix). - Sortable: The large-to-small structure (
YYYY-MM-DD...) means the strings are lexicographically sortable, preserving chronological order.
2. Alternative Method: Unix Timestamp (Number) ⏳
The second common method is to use a JSON number to store the date as a Unix timestamp (also called Epoch Time).
| Format Type | Example | Description |
|---|---|---|
| Milliseconds | 1664521971000 | The number of milliseconds elapsed since the Unix Epoch (January 1, 1970, 00:00:00 UTC). This is preferred. |
| Seconds | 1664521971 | The number of seconds elapsed since the Unix Epoch. |
Pros and Cons of Unix Timestamps:
- Pros: Very compact, efficient for storage, and faster for machine-to-machine comparisons or sorting without needing string parsing.
- Cons: Not human-readable (it's just a large number), and it typically loses the time zone information unless the system has an implicit agreement that the number is always relative to UTC.
Published on: Sep 30, 2025, 07:56 AM