
📎 This article includes 2 downloadable practice files ↓
In this article
“`javascript
const order = { id: “SO-1001”, customer: { name: “Iyer Stores”, city: “Chennai” },
items: [{ p: “Laptop”, q: 2, r: 42000 }] };
order.customer.name; // “Iyer Stores”
const json = JSON.stringify(order); // text, to save or send
const back = JSON.parse(json); // object again
const { customer: { city } } = back; // destructuring
“`
JSON
JavaScript Object Notation is plain text that looks like these objects. APIs, config files and many exports use it. Keys must be in double quotes; no trailing commas.
Useful helpers
Object.keys(o), Object.values(o), Object.entries(o); the optional chaining order.customer?.gstin returns undefined instead of crashing when a property is missing.
Practice
Run the script, then add a second item and print the order total.
📎 Practice files for this article
- 📄js-06-objects-json.jsLesson code file.⬇ JS · 377 B
- 📄js-06-objects-json-output.txtOutput from our test run.⬇ TXT · 137 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.