Practical Reference for Everyday Developer Data: JSON, Regex, Unix Timestamps, Base64 & WCAG Contrast
Quick engineering reference covering common bugs with JSON parsing, regular expression backtracking, 10-digit vs 13-digit Unix timestamps, Base64URL encoding, and WCAG 2.1 contrast ratios.
Key Takeaways
- Distinguish 10-digit Unix seconds from 13-digit JavaScript milliseconds to avoid year-1970 or year-56000 timestamp bugs.
- Use Base64URL (- and _ instead of + and /) when encoding tokens for URLs or JWTs.
- WCAG 2.1 AA requires at least 4.5:1 contrast for normal body text and 3:1 for large headings and UI controls.
1. JSON Pitfalls That Break Production Parsers
Strict RFC 8259 JSON is far less forgiving than JavaScript object literals. Most “Unexpected token” parse errors come from four recurring mistakes:
- Trailing commas:
{"a": 1,}works in JavaScript but is invalid JSON. - Single quotes or unquoted keys: Every property name and string value must use double quotes (
"key"). - Comments: Standard JSON forbids
//and/* */comments (only JSONC/JSON5 parsers accept them). - Unescaped control characters: Raw line breaks inside string values must be escaped as
\n.
2. Regular Expressions: Readability & Backtracking Safety
Regular expressions excel at extracting log tokens and validating formats, but nested quantifiers such as (a+)+$ can cause catastrophic backtracking (ReDoS) when evaluated against non-matching input, hanging a server thread or browser tab.
// Safer explicit pattern for ISO dates (YYYY-MM-DD)
/^(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])$/
Prefer named capture groups ((?<name>...)) for self-documenting matches, avoid overlapping wildcards like .*.*, and always test untrusted inputs with bounded quantifiers.
3. Unix Timestamps: Seconds vs Milliseconds
One of the most frequent timezone bugs across backend APIs and frontend JavaScript is mixing 10-digit Unix seconds with 13-digit milliseconds:
- 10 digits (e.g.,
1795368000): Seconds since1970-01-01T00:00:00Z(common in Python, Go, PostgreSQL, JWTexp/iatclaims). - 13 digits (e.g.,
1795368000000): Milliseconds since epoch (JavaScriptDate.now(), JavaSystem.currentTimeMillis()). - Best practice for storage & logs: Always store UTC epoch or ISO-8601 with explicit offset (
2026-11-22T18:00:00Z), and convert to an IANA timezone likeAsia/KolkataorAmerica/New_Yorkonly at display time.
4. Base64 vs Base64URL vs URL Percent-Encoding
Encoding transforms data safely for transport — it is never encryption. Picking the wrong encoder causes subtle token corruption:
- Standard Base64: Uses
+,/, and=padding. If placed directly into a URL query parameter,+is often decoded as a space. - Base64URL (RFC 4648 §5): Replaces
+with-,/with_, and omits=padding — required for JWT headers and payloads. encodeURIComponent(): Use for individual query values; useencodeURI()only when preserving full URL delimiters like?and&.
5. WCAG 2.1 Color Contrast Ratios at a Glance
Readable typography improves usability for everyone, especially on mobile screens in bright sunlight. WCAG 2.1 defines minimum luminance contrast ratios between foreground text and background color:
| Content Type | WCAG AA (Standard) | WCAG AAA (Enhanced) |
|---|---|---|
| Normal body text (< 18pt / 24px) | 4.5 : 1 | 7.0 : 1 |
| Large text (≥ 18pt or ≥ 14pt bold) | 3.0 : 1 | 4.5 : 1 |
| UI borders, icons & focus rings | 3.0 : 1 | — |