Cheat Sheets

JavaScript Objects & JSON Cheat Sheet: Keys, Spread, Parse & Stringify

By ArpaNeuro Team September 13, 2026
JavaScript JSON cheat sheet

Objects are unordered string/symbol key maps. JSON is a data format: JSON.stringify and JSON.parse convert to and from strings for APIs and storage. Spread and destructuring copy enumerable own properties; they are shallow copies unless you clone deeper.

This JavaScript cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.

Quick reference

  • Literal: { title: "A", count: 1 } shorthand { title } when the variable name matches.
  • Access: obj.title or obj["title"] for computed keys.
  • Keys: Object.keys, values, entries. Iterate entries in for...of.
  • Spread: const next = { ...prev, title } — shallow. Nested objects stay shared.
  • JSON: JSON.stringify(obj) drops undefined, functions, and symbols.
  • Parse: Wrap JSON.parse in try/catch. Validate shape after parse.
  • Optional: order?.customer?.email avoids Cannot read property of undefined.
  • Clone: structuredClone(obj) for most data. Spread is not deep.

Copy-paste examples

Safe JSON parse and a shallow update

Never JSON.parse untrusted strings without try/catch. Spread does not deep-copy nested objects.

function readSettings(raw) {
  try {
    const data = JSON.parse(raw);
    if (data === null || typeof data !== 'object') return {};
    return data;
  } catch {
    return {};
  }
}
function setTitle(post, title) {
  return { ...post, title, updatedAt: Date.now() };
}

Common mistakes

  • Using JSON.parse on localStorage without try/catch after a user or another tab wrote junk.
  • JSON.stringify of objects with circular refs — it throws.
  • Mutating a nested object after a spread and wondering why React did not re-render.
  • Treating JSON as “JavaScript” and pasting comments or trailing commas into .json files.

FAQ

  1. Object vs Map? Map allows any key (including objects), remembers insertion, and has reliable size. Use objects for records with known string keys.
  1. Why did stringify drop my field? The value was undefined or a function. Use null if the API must see the key.
  1. Deep copy? structuredClone for most app data. Libraries for special cases. JSON round-trip loses dates (they become strings).

Related JavaScript cheat sheets

Build with this stack

When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.

Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.

← All Articles Get a Quote →