Phase 4 · Async, Data & ToolingModule 28~42 min read

JSON, Regex, Dates & Internationalization

Work with everyday application data using JavaScript's standard parsing, matching, date, and locale APIs.

What you'll learn

JSON, regular expressions, dates, and Intl APIs handle everyday data boundaries. Correctness comes from acknowledging each format's limits rather than treating strings as self-explanatory.

By the end of this lesson, you'll be able to:

  • Serialize JSON deliberately
  • Use regex for focused text patterns
  • Format dates and numbers by locale

Core mental model

Use this decision table as a compact reference. Focus on what each tool means and when it earns its place in production code.

ConceptWhat it meansDecision rule
JSONPortable text format with limited value typesValidate parsed structure before use
RegExpPattern language for text matchingUse for local syntax, not full semantic parsing
IntlLocale-aware presentation APIsStore canonical data; format only at display boundaries

Professional workflow

Build the behavior in small, observable steps. Each step should leave something you can inspect or test.

  1. Describe the application data transformation boundary: inputs, outputs, state, timing, and expected failures.
  2. Implement the smallest correct path with names that expose intent.
  3. Add edge cases and failure handling before introducing abstractions.
  4. Verify behavior with realistic data and one deliberately adversarial example.
  5. Refactor only after the observable behavior is protected.

Make behavior observable

Before optimizing or abstracting, make inputs, outputs, state changes, timing, and failure paths visible. JavaScript becomes much easier to reason about when hidden work is exposed.

Guided code lab

Serialize with a controlled shape

A replacer removes implementation fields before transport.

json.js
const record = { id: 4, title: "Async", internalToken: "secret" };
const json = JSON.stringify(record, ["id", "title"], 2);
console.log(json);

Format canonical values for a locale

The underlying amount and instant stay machine-friendly.

intl.js
const amount = 1234.5;
const instant = new Date("2026-08-25T09:00:00Z");
console.log(new Intl.NumberFormat("en-US", {
  style: "currency", currency: "USD",
}).format(amount));
console.log(new Intl.DateTimeFormat("en-GB", {
  dateStyle: "medium", timeZone: "UTC",
}).format(instant));

Production practice

Contract

Document the application data transformation inputs, completion signal, failure channel, ordering, and cancellation behavior.

Verification

Test success, expected failure, timeout or cancellation, empty data, and out-of-order completion.

Operations

Expose duration and failure context without logging secrets or overwhelming the main thread.

Common failure mode

Parsing an ambiguous local date string can produce different instants across environments; exchange ISO timestamps with explicit offsets.

Independent workshop

Normalize and present an imported order feed.

Your finished workshop must include:

  • Validated JSON shape
  • A focused identifier regex
  • Locale-aware currency and date display

Definition of done

Demonstrate the happy path and at least two edge cases, keep responsibilities separated, and add a short note explaining one design choice.

Recap & quick check

Key takeaways

  • JSON drops unsupported values
  • Parsed data is untrusted
  • Regex matches text patterns
  • Intl separates canonical storage from presentation

Quick check

1. Can JSON represent undefined directly?

2. Should formatted currency be stored as the numeric source of truth?

3. What should follow JSON.parse?

Keep the workshop. Later modules deliberately build on these decisions, so each exercise can become part of your final portfolio architecture.