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.
| Concept | What it means | Decision rule |
|---|---|---|
| JSON | Portable text format with limited value types | Validate parsed structure before use |
| RegExp | Pattern language for text matching | Use for local syntax, not full semantic parsing |
| Intl | Locale-aware presentation APIs | Store 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.
- Describe the application data transformation boundary: inputs, outputs, state, timing, and expected failures.
- Implement the smallest correct path with names that expose intent.
- Add edge cases and failure handling before introducing abstractions.
- Verify behavior with realistic data and one deliberately adversarial example.
- Refactor only after the observable behavior is protected.
Make behavior observable
Guided code lab
Serialize with a controlled shape
A replacer removes implementation fields before transport.
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.
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
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
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.