Dates in JSON, and the type a generator should give you
JSON has no date. What you get depends on the format in your sample, and an epoch number is almost always missed.
JSON has six types: object, array, string, number, boolean and null. A date is not one of them. So every date in JSON is wearing a costume, and a generator has to recognise the costume to give you a real date type.
The costumes
{
"iso": "2026-02-01T10:00:00Z",
"iso_offset": "2026-02-01T15:30:00+05:30",
"date_only": "2026-02-01",
"epoch_seconds": 1770000000,
"epoch_millis": 1770000000000,
"human": "1 Feb 2026",
"dotnet": "/Date(1770000000000)/"
}
Open this example in the tool →
A good generator finds the first three. It gives you Date, time.Time,
datetime or Date? depending on the language, and writes the parsing code
with it.
It will miss the rest. epoch_seconds is a number, so you get int64.
human is a string, so you get string. dotnet is a string with a number
hiding inside a bracket.
Why the epoch case matters most
An epoch number is extremely common — every Unix tool, most log formats, the
Stripe API, the GitHub API in places — and it is the one a generator cannot
guess, because 1770000000 is a perfectly good number on its own. A field
called count with that value must stay a number.
So the type you get is int64, and the conversion lives in your head instead
of in the code. Three months later somebody passes milliseconds to the
function that expects seconds, and your record is dated 1970 or 58000.
Two defences:
- Name the field so the unit is in the name.
created_at_ms, notcreated. The next person cannot get it wrong. - Convert at the edge. The moment you read the data, turn the number into your language's date type, and never pass the raw number further in.
This tool will learn to spot an epoch number and offer the date type for it. A value between about 1,000,000,000 and 4,000,000,000 is almost certainly seconds; the same value times a thousand is almost certainly milliseconds.
A date with no time is not a moment
2026-02-01 is a day, not a point in time. Turning it into a Date or a
datetime adds a time of midnight and, worse, a time zone that was never
there. A birthday read as midnight UTC is the day before in India.
Use the type your language has for a plain date, when it has one:
| Language | A moment | A day |
|---|---|---|
| Python | datetime |
date |
| Java | Instant, OffsetDateTime |
LocalDate |
| C# | DateTimeOffset |
DateOnly |
| Go | time.Time |
time.Time, by convention at midnight UTC |
| Rust | DateTime<Utc> |
NaiveDate |
| TypeScript | Date |
nothing. Keep the string |
TypeScript has no date-only type at all. Keeping "2026-02-01" as a string is
honest, and it sorts correctly as text, which a Date does not do any better.
The offset is information, do not throw it away
2026-02-01T15:30:00+05:30 and 2026-02-01T10:00:00Z are the same moment.
They are not the same fact: the first also tells you the event happened at
half past three in the afternoon, where the user was.
If you parse into a type that only holds UTC, that second fact is gone and you
cannot get it back. Java's OffsetDateTime and C#'s DateTimeOffset keep it.
JavaScript's Date does not. Store the original string next to the parsed
value when the local time matters — for an appointment, a shift, a delivery
window.
What to check in the code you get
- Is every date field a date type, or did one stay a string or a number?
- Does a date-only field have a time attached that nobody wrote?
- Does the parsing accept only the format your API sends, or anything?
z.coerce.date()in Zod accepts a great deal, including"hello"? No — but it accepts many formats that are not ISO-8601, which may hide a change in the API from you.
Try it
Paste the seven-field sample above into the tool. Switch between TypeScript, Go and Python and see exactly which three fields became dates and which four did not. That picture is worth more than this whole page.
Try it on your own JSON. The generator runs in your browser. Nothing is uploaded, and nothing is stored on a server.
Open JSON to CodeRead next
snake_case to camelCase — what a generator renames, and why
Your JSON keys and your language's naming rules disagree. Here is what gets renamed, what keeps the original name, and where it goes wrong.
When one field holds two types
An array of mixed things, a field that is a string on Monday and a number on Tuesday. What a generator does, and what you should do instead.
Which JSON fields are optional? What a generator can and cannot know
A sample shows you what was there once. It cannot show you what is always there. Here is how to tell the difference, and what to do about it.