Book Image

JavaScript and JSON Essentials

By : Sai S Sriparasa
Book Image

JavaScript and JSON Essentials

By: Sai S Sriparasa

Overview of this book

The exchange of data over the Internet has been carried out since its inception. Delimiter-separated lists such as CSV and tag-separated languages such as XML are very popular, yet they are considered to be verbose by a section of developers. JSON (JavaScript Object Notation) is a lightweight text-based code to create objects to transfer data over the Internet. It is a data exchange format that is human-readable (like XML, but without the markup around your actual payload) and its syntax is a subset of the JavaScript language that was standardized in 1999. JavaScript and JSON Essentials is a step-by-step guide that will introduce you to JSON and help you understand how the lightweight JSON data format can be used in different ways either to store data locally or to transfer data over the Internet. This book will teach you how to use JSON effectively with JavaScript. This book begins with a brief refresher course on JavaScript before taking you through how JSON data can be transferred via synchronous, asynchronous, and cross-domain asynchronous HTTP calls. JSON is not just about data transfer; this book throws light on the alternate implementations of JSON as well. You will learn the data types that JavaScript uses and how those data types can be used in JSON. You will go through the concepts of how to create, update, parse, and delete a JSON object. You will also look at the different techniques of loading a JSON file onto a web page, how to use jQuery to traverse through an object, and how to perform access operations. You will also go over a few resources that will make debugging JSON quick and easy.
Table of Contents (15 chapters)


JavaScript and JSON Essentials is a one-stop resource that can be used for understanding and implementing JSON in various web applications. This book provides a comprehensive insight into how JSON can be implemented and integrated into your applications. Though JSON is one of the most popular data-exchange formats, the number of books available describing JSON and helping readers build a live solution is not high. This book is a comprehensive guide to JSON that begins with JavaScript basics, discusses the history of JSON, and then takes a step-by-step approach towards using JSON to build a live web application that is powered by JSON data.

What this book covers

Chapter 1, JavaScript Basics, is a basic refresher for common JavaScript concepts.

Chapter 2, Getting Started with JSON, introduces the audience to JSON, discusses the history of JSON, outlines the popular programming languages that support JSON, fires a Hello World program in JSON, and writes basic programs with different data types in JSON.

Chapter 3, Working with Real-time JSON, introduces the audience to complex JSON. The JSON used in this chapter will consist of multiple datatypes and multiple objects and will be multidimensional.

Chapter 4, AJAX Calls with JSON Data, goes over the requirements to successfully pass JSON over HTTP as JSON data has to transported over HTTP in real-world scenarios.

Chapter 5, Cross-domain Asynchronous Requests, introduces the audience to the concept of making asynchronous calls across domains. Since data is being transported across domains, users will be introduced to the concept of JSON with Padding.

Chapter 6, Building the Carousel Application, discusses the idea of a Carousel application and the required setup and dependencies such as, jQuery library, and jQuery Cycle plugin for the application.

Chapter 7, Alternate Implementations of JSON, discusses the non web-development implementation of JSON such as dependency managers, metadata stores, and configuration stores. The discussion would go forward and talk about the advantages of JSON over XML and YAML.

Chapter 8, Debugging JSON, introduces the powerful tools that are available to debug, validate, and format JSON. As the number of objects increases, the length of JSON increases too, which makes it difficult for the naked eye to validate JSON.

What you need for this book

JSON is language-and platform-independent, so readers can use an operating system of their choice. To serve live JSON, we need a live web server. There are parsers available for most of the popular server-side languages; readers can use a web server such as Apache, Tomcat, IIS, or any other web server and can pick a text editor of their choice.

Who this book is for

This book has been designed to cater to the needs of developers at all levels. This book contains numerous working examples, tips, and notes that will guide users through all the chapters. It is not required but would be good to have some knowledge about HTML and JavaScript. Some familiarity with server-side languages such as PHP, C#, or Python would be preferred, but not required.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code and the output being generated by the code are added to the book as screenshots. The name of the file will be shown as follows:.


New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: “Load the file in a web browser, and a pop-up box with the text Hello World! should be loaded on the page”.


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.