When Objects Still Win: JSON and Plain Data
You'll learn: When plain objects are still the better choice despite the power of Maps and Sets.
The Right Tool for the Job
Maps and Sets are powerful, but plain objects haven't lost their usefulness. Two scenarios where objects clearly win are JSON serialization and simple data structures.
JSON and Objects Are Best Friends
JSON (JavaScript Object Notation) only understands plain objects and arrays. When you need to send data over the network or save it to a file, JSON.stringify() works seamlessly with objects but completely ignores Maps and Sets:
const userObject = { name: "Alice", age: 30 };
console.log(JSON.stringify(userObject));
// "{"name":"Alice","age":30}" ✓ works perfectly
const userMap = new Map([["name", "Alice"], ["age", 30]]);
console.log(JSON.stringify(userMap));
// "{}" ✗ empty! Map data is lost
Simple, Fixed Data Structures
When you have simple configuration data or fixed-structure records with string keys, objects are cleaner and more intuitive:
// Clean and obvious
const config = {
apiUrl: "https://api.example.com",
timeout: 5000,
retries: 3
};
// Overkill with Map
const configMap = new Map([
["apiUrl", "https://api.example.com"],
["timeout", 5000],
["retries", 3]
]);
Objects give you literal syntax, immediate readability, and universal compatibility with JSON APIs and serialization.
Key Takeaway: Use plain objects when you need JSON compatibility or simple, fixed data structures with string keys. Save Maps for dynamic key-value stores with non-string keys or performance-critical lookups.