SlideShare a Scribd company logo
2
Most read
4
Most read
Introduction to JavaScript Object Notation, Lindsay Bassett, 2015
978-1-491-92948-3
[LSI]
Introduction to JavaScript Object Notation
by Lindsay Bassett
Copyright © 2015 Lindsay Bassett. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editor: Meg Foley
Production Editor: Kristen Brown
Copyeditor: Jasmine Kwityn
Proofreader: Charles Roumeliotis
Indexer: Ellen Troutman
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Rebecca Demarest
August 2015: First Edition
Revision History for the First Edition
2015-08-04: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491929483 for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Introduction to JavaScript Object Nota‐
tion, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and the author disclaim all responsibility
for errors or omissions, including without limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and instructions contained in this work is at your own
risk. If any code samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
1. What Is JSON?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
JSON Is a Data Interchange Format 1
JSON Is Programming Language Independent 2
Key Terms and Concepts 4
2. JSON Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
JSON Is Based on JavaScript Object Literals 5
Name-Value Pairs 6
Proper JSON Syntax 7
Syntax Validation 10
JSON as a Document 11
The JSON MediaType 11
Key Terms and Concepts 11
3. JSON Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Quick Look at Data Types 13
The JSON Data Types 15
The JSON Object Data Type 16
The JSON String Data Type 17
The JSON Number Data Type 19
The JSON Boolean Data Type 20
The JSON Null Data Type 20
The JSON Array Data Type 21
Key Terms and Concepts 26
iii
4. JSON Schema. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Contracts with Validation Magic 30
Introduction to JSON Schema 31
Key Terms and Concepts 36
5. JSON Security Concerns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
A Quick Look at Client- and Server-Side Relationships 39
Cross-Site Request Forgery (CSRF) 40
Injection Attacks 43
Cross-Site Scripting (XSS) 43
Holes in Security: Architectural Decisions 45
Key Terms and Concepts 46
6. The JavaScript XmlHttpRequest and Web APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Web APIs 50
The JavaScript XMLHttpRequest 53
Relationship Woes and Rules About Sharing 57
Cross-Origin Resource Sharing (CORS) 57
JSON-P 58
Key Terms and Concepts 60
7. JSON and Client-Side Frameworks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
jQuery and JSON 64
AngularJS 66
Key Terms and Concepts 71
8. JSON and NoSQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
The CouchDB Database 74
The CouchDB API 77
Key Terms and Concepts 85
9. JSON on the Server Side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Serializing, Deserializing and Requesting JSON 88
ASP.NET 88
PHP 92
A Smorgasbord of JSON HTTP Requests 96
Ruby on Rails 97
Node.js 98
Java 98
Key Terms & Concepts 99
iv | Table of Contents
10. Conclusion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
JSON as a Configuration File 101
The Big Picture 104
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Table of Contents | v

More Related Content

Similar to Introduction to JavaScript Object Notation, Lindsay Bassett, 2015 (20)

PDF
Web_Development_with_Node_Express.pdf
Marco Antonio Martinez Andrade
 
PDF
Mysql In A Nutshell In A Nutshell Oreilly Second Edition Russell Dyer
atchaaslaney
 
PDF
Javascript Web Applications Otx Alex Maccaw
fahradzereit93
 
PDF
Building Hypermedia Apis With Html5 And Node Mike Amundsen
goorgaudias
 
PDF
Nodejs For Php Developers Porting Php To Nodejs 1st Edition Daniel Howard
ingrimyayo
 
PDF
High Performance JavaScript Build Faster Web Application Interfaces 1st Editi...
yarecofuxxa58
 
PDF
JavaScript 设计模式
guest97dcac3
 
PDF
[Web开发Css系列].Apress.Pro.Css.Techniques.Nov.2006
bmchaoshi
 
PDF
Brian.suda.thesis
Aravindharamanan S
 
PDF
C# 10 in a Nutshell_ The Definitive Reference-O'Reilly Media (2022).pdf
ssuser2a88da1
 
PDF
Programming Coldfusion Mx 2nd Edition Rob Brooksbilson
kurohaost
 
PDF
Advanced Java Script.pdf
Sophia Diaz
 
PDF
Enterprise Javabeans 31 Sixth Edition Andrew Lee Rubinger Bill Burke
khatraowoses
 
PDF
Learning Rails 3 Rails from the Outside In 1st Edition Simon St. Laurent
tobarpaolico
 
PDF
Beginning Java Me Platform 1st Edition Ray Rischpater
aqvtrealj082
 
PDF
Martin Kleppmann-Designing Data-Intensive Applications_ The Big Ideas Behind ...
Samir P.
 
PDF
Mongo db manual
Dan Llimpe
 
PDF
Mongo db manual
Deysi Gmarra
 
Web_Development_with_Node_Express.pdf
Marco Antonio Martinez Andrade
 
Mysql In A Nutshell In A Nutshell Oreilly Second Edition Russell Dyer
atchaaslaney
 
Javascript Web Applications Otx Alex Maccaw
fahradzereit93
 
Building Hypermedia Apis With Html5 And Node Mike Amundsen
goorgaudias
 
Nodejs For Php Developers Porting Php To Nodejs 1st Edition Daniel Howard
ingrimyayo
 
High Performance JavaScript Build Faster Web Application Interfaces 1st Editi...
yarecofuxxa58
 
JavaScript 设计模式
guest97dcac3
 
[Web开发Css系列].Apress.Pro.Css.Techniques.Nov.2006
bmchaoshi
 
Brian.suda.thesis
Aravindharamanan S
 
C# 10 in a Nutshell_ The Definitive Reference-O'Reilly Media (2022).pdf
ssuser2a88da1
 
Programming Coldfusion Mx 2nd Edition Rob Brooksbilson
kurohaost
 
Advanced Java Script.pdf
Sophia Diaz
 
Enterprise Javabeans 31 Sixth Edition Andrew Lee Rubinger Bill Burke
khatraowoses
 
Learning Rails 3 Rails from the Outside In 1st Edition Simon St. Laurent
tobarpaolico
 
Beginning Java Me Platform 1st Edition Ray Rischpater
aqvtrealj082
 
Martin Kleppmann-Designing Data-Intensive Applications_ The Big Ideas Behind ...
Samir P.
 
Mongo db manual
Dan Llimpe
 
Mongo db manual
Deysi Gmarra
 

Recently uploaded (20)

PDF
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Best Web development company in india 2025
Greenusys
 
PDF
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PPTX
Prompt Like a Pro. Leveraging Salesforce Data to Power AI Workflows.pptx
Dele Amefo
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PDF
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PDF
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
PPTX
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PPTX
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
PPTX
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
AI Prompts Cheat Code prompt engineering
Avijit Kumar Roy
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Best Web development company in india 2025
Greenusys
 
IObit Driver Booster Pro 12.4.0.585 Crack Free Download
henryc1122g
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
UITP Summit Meep Pitch may 2025 MaaS Rebooted
campoamor1
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Prompt Like a Pro. Leveraging Salesforce Data to Power AI Workflows.pptx
Dele Amefo
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
Dipole Tech Innovations – Global IT Solutions for Business Growth
dipoletechi3
 
BB FlashBack Pro 5.61.0.4843 With Crack Free Download
cracked shares
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
Ad

Introduction to JavaScript Object Notation, Lindsay Bassett, 2015

  • 2. 978-1-491-92948-3 [LSI] Introduction to JavaScript Object Notation by Lindsay Bassett Copyright © 2015 Lindsay Bassett. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editor: Meg Foley Production Editor: Kristen Brown Copyeditor: Jasmine Kwityn Proofreader: Charles Roumeliotis Indexer: Ellen Troutman Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest August 2015: First Edition Revision History for the First Edition 2015-08-04: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781491929483 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Introduction to JavaScript Object Nota‐ tion, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
  • 3. Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii 1. What Is JSON?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 JSON Is a Data Interchange Format 1 JSON Is Programming Language Independent 2 Key Terms and Concepts 4 2. JSON Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 JSON Is Based on JavaScript Object Literals 5 Name-Value Pairs 6 Proper JSON Syntax 7 Syntax Validation 10 JSON as a Document 11 The JSON MediaType 11 Key Terms and Concepts 11 3. JSON Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Quick Look at Data Types 13 The JSON Data Types 15 The JSON Object Data Type 16 The JSON String Data Type 17 The JSON Number Data Type 19 The JSON Boolean Data Type 20 The JSON Null Data Type 20 The JSON Array Data Type 21 Key Terms and Concepts 26 iii
  • 4. 4. JSON Schema. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Contracts with Validation Magic 30 Introduction to JSON Schema 31 Key Terms and Concepts 36 5. JSON Security Concerns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 A Quick Look at Client- and Server-Side Relationships 39 Cross-Site Request Forgery (CSRF) 40 Injection Attacks 43 Cross-Site Scripting (XSS) 43 Holes in Security: Architectural Decisions 45 Key Terms and Concepts 46 6. The JavaScript XmlHttpRequest and Web APIs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Web APIs 50 The JavaScript XMLHttpRequest 53 Relationship Woes and Rules About Sharing 57 Cross-Origin Resource Sharing (CORS) 57 JSON-P 58 Key Terms and Concepts 60 7. JSON and Client-Side Frameworks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 jQuery and JSON 64 AngularJS 66 Key Terms and Concepts 71 8. JSON and NoSQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 The CouchDB Database 74 The CouchDB API 77 Key Terms and Concepts 85 9. JSON on the Server Side. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Serializing, Deserializing and Requesting JSON 88 ASP.NET 88 PHP 92 A Smorgasbord of JSON HTTP Requests 96 Ruby on Rails 97 Node.js 98 Java 98 Key Terms & Concepts 99 iv | Table of Contents
  • 5. 10. Conclusion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 JSON as a Configuration File 101 The Big Picture 104 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Table of Contents | v