Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Ben Smith

JSON (javascript Object Notation) — текстовый формат обмена данными, основанный на javascript. Beginning JSON is the definitive guide to JSON - todays standard in data formatting for the web. The book starts with the basics, and walks you through all aspects of using the JSON format.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Beginning JSON — Reading Guide ## 【One-Line Pitch】 A practical, hands-on introduction to JSON as both a JavaScript concept and a universal data interchange format, ideal for web developers who want to understand serialization, parsing, and real-world data exchange from the ground up. ## 【Book Arc】 - **Opening (~0%–10%)**: JavaScript fundamentals — strings, quoting and escaping rules, primitive types, expressions, operators, and statement syntax. This stage builds the language foundation JSON depends on. - **Early (~10%–23%)**: Objects and arrays as JavaScript data structures, including object/array literals, property access, and the String object's full method interface (indexOf, match, replace, slice, split, etc.). - **Early (~23%–29%)**: Introducing JSON itself — its history (Douglas Crockford, RFC 4627, ECMA-404), grammar, composite structures, and valid JSON values. Establishes JSON as a subset of JavaScript, not a programming language. - **Middle (~29%–42%)**: Serialization with JSON.stringify — how JavaScript values become JSON text, handling edge cases, using the replacer parameter for whitelisting properties, and the space parameter for formatting. Also covers browser support for the native JSON object. - **Middle (~42%–48%)**: Deserialization with JSON.parse — converting JSON text back into JavaScript data trees, accessing members via dot/bracket notation, and using the reviver function to transform values (e.g., converting ISO date strings into Date objects). - **Late (~48%+)**: Persisting JSON — storing serialized data for application state and interchange, moving from in-memory structures to durable storage. ## 【Key Takeaways】 - **JSON is a subset of JavaScript, not a language of its own** (Early): It inherits JavaScript's literal syntax but functions purely as a data interchange format. This distinction matters because it explains both JSON's simplicity and its limitations — you can't put functions or undefined values in JSON. - **Quoting and escaping are the first practical hurdle** (Opening): Nested quotes inside strings confuse parsers; alternating quote styles or backslash escaping (`\"`) solves this. This is foundational because JSON strings follow the same rules. - **Objects and arrays are the two composite structures JSON builds on** (Early): Objects are string/value pairs; arrays are ordered integer-keyed collections. Understanding their JavaScript forms directly maps to understanding JSON's grammar. - **JSON.stringify handles serialization, but not all values serialize as expected** (Middle): The replacer parameter lets you whitelist which properties get serialized — useful when you need to exclude sensitive data like email addresses without deleting them from the source object. - **JSON.parse reverses the process and returns a live data tree** (Middle): After parsing, you access members with dot notation (`author.name`) or bracket notation (`author.pets[0].name`). The parsed result is a plain JavaScript object, not a special JSON type. - **The reviver function transforms values during parsing** (Middle): A common use case is detecting ISO-formatted date strings via regular expressions and converting them into actual Date objects — something JSON.stringify does not preserve natively. - **Native JSON support is built into modern browsers** (Middle): Firefox 3.5+, Chrome 5+, Safari 4.0.5+, Opera 10.5+, and IE 8+ all include the JSON object natively; the downloadable JSON library simply checks for existing support before creating a fallback. ## 【Reading Tips】 - **Skim Chapter 1–2 if you already know JavaScript basics**: The early chapters cover strings, operators, and object/array literals thoroughly — useful for beginners, but experienced developers can jump ahead to Chapter 4 where JSON is formally introduced. - **Deep-read Chapter 5 (stringify) and Chapter 6 (parse)**: These are the practical core. Pay special attention to the replacer and reviver parameters — they solve real-world problems like excluding sensitive fields and restoring date objects. - **Work through the exercises**: The book includes hands-on exercises (e.g., Exercise 5-1) that involve creating HTML files and experimenting with serialization. These cement the concepts better than passive reading. - **Watch for the "subset" theme**: The book repeatedly emphasizes that JSON is a subset of JavaScript. Keep this in mind when you encounter values that don't serialize as expected — it explains why functions, undefined, and certain objects behave oddly. - **Note the browser support table**: If you're supporting older browsers, the compatibility table in Chapter 5 tells you when you need the JSON library fallback versus when native support suffices. ## 【Coverage Limits】 The excerpts cover JavaScript fundamentals, JSON grammar and history, stringify/parse mechanics, and persistence concepts. They do not cover advanced topics like JSON Schema validation, JSON in specific frameworks, or performance optimization at scale. ##
Page 19
e the string ends prematurely, as in the preceding example. There are two possible ways to accomplish this. Alternate Quotations Because you can alternate be...
View in text
Excerpt 2
reflect their index within the collection. Object Literals Object (with an initial capital letter) refers to the JavaScript Object type. An object refers to...
View in text
Excerpt 3
[{"name":"Waverly","age":3.5},{"name":"Westley","age":4}]}" The produced JSON captures the data precisely as it was housed within the author object. The grea...
View in text
Excerpt 4
ts[0].name) // Waverly; The magic of JSON.parse is twofold. The first proponent that allows for the transformation of JSON text into that of a JavaScript val...
View in text
Excerpt 5
itially assigned. This is strictly due to the fact that the cookie-av values are intended to be utilized by the browser alone. It is the browser’s job to ens...
View in text
Excerpt 6
main object-oriented and register the event of the state to which we choose to listen. For each event to which we listen, we can assign a particular function...
View in text
Excerpt 7
ess http://json.sandboxed.guru/chapter8/. Upon a successful reception of the request, the server would respond in kind with an entity body, which could be us...
View in text
Excerpt 8
the former option (the query string parameter). Listing 9-7. An xhr object Whose Target Resource Possesses a Query String Parameter Indicating the URI for th...
View in text
Tags
AI categories
Programming LanguageJavaScriptWeb Technology
ISBN: 1484202031
Publisher: Apress
Publish Year: 2015
Language: English
Pages: 324
File Format: PDF
File Size: 7.1 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…