learn.fttgsolutions.com · Cheat Sheets
Structure. Exchange. Parse.
Data Types
| String | "hello world" | A sequence of Unicode characters wrapped in double quotes. Single quotes are NOT valid in JSON. |
| Number (integer) | 42 | A whole number. Can be positive or negative. Hexadecimal (0xFF) is NOT allowed. |
| Number (decimal) | 3.14 | A floating-point number with a decimal fraction. |
| Number (exponent) | 1.5e10 | Scientific notation using e, e+, e-, E, E+, or E. |
| Boolean | true / false | Lowercase only. true or false — no quotes, no capitals. |
| Null | null | Represents an empty or non-existent value. Lowercase only. |
| Object | { "key": "value" } | An unordered collection of key/value pairs wrapped in curly braces. Keys must be strings. |
| Array | [1, "two", true] | An ordered list of values wrapped in square brackets. Values can be any JSON type. |
Object Syntax
| Basic object | { "name": "Alice", "age": 30 } | Key/value pairs separated by commas. Keys must be double-quoted strings. |
| Nested object | { "user": { "id": 1, "role": "admin" } } | Objects can contain other objects as values. |
| Empty object | {} | A valid JSON object with no properties. |
| Mixed types | { "name": "Bob", "score": 95, "active": true, "notes": null } | Values in one object can be different types. |
Array Syntax
| Basic array | [1, 2, 3, 4, 5] | An ordered list of values. Begins with [ and ends with ]. |
| Mixed array | [1, "hello", true, null] | Arrays can contain values of different types. |
| Array of objects | [{ "id": 1 }, { "id": 2 }] | A common pattern — each element is an object, great for lists of records. |
| Object of arrays | { "tags": ["a", "b", "c"] } | An object whose property value is an array. |
| 2D array | [[1, 2], [3, 4], [5, 6]] | Arrays can nest other arrays to create multi-dimensional structures. |
| Empty array | [] | A valid JSON array with no elements. |
String Escape Sequences
| Double quote | \" | Escape a literal double quote inside a JSON string. |
| Backslash | \\ | Escape a literal backslash inside a JSON string. |
| Forward slash | \/ | Optionally escape a forward slash — useful in HTML contexts. |
| Newline | \n | Insert a line break inside a string value. |
| Carriage return | \r | Insert a carriage return inside a string value. |
| Tab | \t | Insert a horizontal tab inside a string value. |
| Backspace | \b | Insert a backspace character inside a string value. |
| Form feed | \f | Insert a form feed character inside a string value. |
| Unicode | \u0041 | Insert a Unicode character using \u followed by exactly four hex digits. Example: \u0041 = 'A'. |
JavaScript — Parse & Stringify
| Parse string → object | const obj = JSON.parse(jsonString); | Converts a JSON string into a JavaScript object. Throws SyntaxError if the string is invalid JSON. |
| Stringify object → string | const str = JSON.stringify(obj); | Converts a JavaScript object into a JSON string. |
| Pretty print | JSON.stringify(obj, null, 2); | Third argument sets indentation (2 or 4 spaces). Produces human-readable output. |
| Replacer filter | JSON.stringify(obj, ['name', 'age']); | Second argument can be an array of keys to include, or a function to transform values. |
| Reviver function | JSON.parse(str, (key, val) => val); | Second argument to JSON.parse — a function called for each key/value to transform the result. |
| Deep clone | const clone = JSON.parse(JSON.stringify(obj)); | A simple way to deep-copy a plain object. Does NOT work for functions, Dates, or undefined values. |
Accessing Data (JavaScript)
| Dot notation | obj.name | Access an object property by name. Returns undefined for missing properties. |
| Bracket notation | obj["name"] | Access a property using a string key. Required when the key contains spaces or special characters. |
| Nested object | obj.user.address.city | Chain dot notation to drill into nested objects. |
| Array index | arr[0] | Access the first element of an array. Arrays are zero-indexed. |
| Array of objects | arr[1].name | Access the name property of the second element in an array of objects. |
| Optional chaining | obj?.user?.city | Safely access nested properties — returns undefined instead of throwing if a middle value is null/undefined. |
Common Mistakes
| Single quotes | { "key": 'value' } ← INVALID | All strings in JSON must use double quotes. Single quotes are not allowed. |
| Trailing comma | { "a": 1, } ← INVALID | JSON does not allow trailing commas after the last property or element. |
| Unquoted key | { key: "value" } ← INVALID | Object keys must always be double-quoted strings. |
| Hex number | { "n": 0xFF } ← INVALID | Only decimal numeric literals are allowed. Hexadecimal, octal, and binary are not valid JSON. |
| Undefined | { "val": undefined } ← INVALID | undefined is not a JSON type. Use null instead. |
| Comments | // comments are NOT allowed | JSON has no comment syntax. Use a separate documentation field if needed. |