JSON often string-encodes complex data types, such as date-times. When coding, we would like to use our programming language's native types, not strings. quicktype lets us do that.
In this blog post, we explain how quicktype's string type transformation works and how to take advantage of it.
The Problem
JSON has limited types: strings, numbers, booleans, null, arrays, and objects. Rich data types like dates, UUIDs, and URIs are typically encoded as strings:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"createdAt": "2018-09-01T12:00:00Z",
"website": "https://quicktype.io",
"email": "hello@quicktype.io"
}
Without transformation, these become plain strings in your code, losing type safety and convenience methods.
The Solution: Transformed String Types
quicktype automatically detects common string formats and converts them to appropriate native types:
- ISO 8601 dates →
Date/DateTime/time.Time - UUIDs →
UUID/Guid - URIs →
URL/Uri - Integers in strings →
Int/Long
Example Output
For Swift:
struct Record: Codable {
let id: UUID
let createdAt: Date
let website: URL
let email: String // No standard email type, stays as String
}
For C#:
public class Record
{
public Guid Id { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public Uri Website { get; set; }
public string Email { get; set; }
}
Controlling Transformations
You can disable transformations if you prefer plain strings:
quicktype data.json --no-date-times --no-uuids -o Types.swift
Or enable specific ones:
quicktype data.json --detect-maps --no-integer-strings -o Types.ts
How Detection Works
quicktype uses pattern matching on string values:
- UUIDs: 8-4-4-4-12 hexadecimal format
- Dates: ISO 8601 patterns (YYYY-MM-DD, YYYY-MM-DDTHH:MM:SS, etc.)
- URIs: Valid URI scheme followed by ://
- Integer strings: All-digit strings that fit in 64 bits
This gives you the best of both worlds: JSON's universal compatibility and your language's type safety.