Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
JavaScript and JSON Essentials
JavaScript and JSON Essentials

JavaScript and JSON Essentials: Build light weight, scalable, and faster web applications with the power of JSON , Second Edition

Arrow left icon
Profile Icon Sai S Sriparasa Profile Icon Joseph D'mello
Arrow right icon
$17.99 $25.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (2 Ratings)
eBook Apr 2018 226 pages 2nd Edition
eBook
$17.99 $25.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Sai S Sriparasa Profile Icon Joseph D'mello
Arrow right icon
$17.99 $25.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5 (2 Ratings)
eBook Apr 2018 226 pages 2nd Edition
eBook
$17.99 $25.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$17.99 $25.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

JavaScript and JSON Essentials

The JSON Structures

In Chapter 1, Getting Started with JSON, you were introduced to basic JSON, how JSON objects can be embedded into an HTML file, and how basic operations such as accessing keys can be performed on simple JSON objects. Now it's time to move ahead with some simple yet advanced steps. In this chapter, you will learn about:

  • Inserting external JavaScript
  • Accessing multilevel JSON objects
  • Performing modifications in JSON data

Now let's take a step forward and work with JSON objects that are bigger, more complex, and closer to the JSON that we would work with in real-world situations.

Inserting external JavaScript

In real-world applications, JSON can be retrieved either as a response from an asynchronous request or from a JSON feed. A website uses HTML, CSS, and JavaScript to provide a visually beautiful user interface. But there are cases where data vendors are only focused on getting data. A data feed serves their purpose; a feed is a crude way of supplying data so that others can reuse it to display the data on their websites or to ingest the data and run their algorithms on it. Such data feeds are big and cannot be directly embedded into the script tag. Let us look at how external JavaScript files can be included in an HTML file.

The following screenshot depicts the code for the external-js.html file:

<!DOCTYPE html>
<html>
<head>
<title>Include external javascript</title>
<script type="text/javascript" src=&quot...

Accessing objects in JSON

Now that we understand how to make a script call to fetch an external JavaScript file, let us use the same technique to import a JSON feed. I have generated a test employee JSON data feed with 100 records. To traverse through any JSON feed, it is important to make a note of how the data is arranged. The keys in this data feed are basic employee information such as employee number, date of birth, first name, last name, gender, hire date, titles that they have held, and the dates during which they have held those titles. A few employees have held the same title throughout their tenure, while there are some employees who have held more than one title.

This JSON file will be part of the code files for exercises.

Consider the following JSON store that we need to use to perform the operations:

let data_json = [
{
"emp_no" : "10001",
...

Performing complex operations

To tackle an array of objects, we have to handle them in an iterative method. We will have to come up with an iterative solution in which we target one object at a time; once the object is accessed, we will not target that object again. This allows us to maintain data integrity as we can avoid accessing the same object multiple times, thereby avoiding any redundancies. The looping statements in JavaScript are the while loop and the for loop. Let us take a quick look at how we can use these looping techniques to traverse through our employee's array:

<!DOCTYPE html>
<html>
<head>
<title>Test Javascript</title>
<script type="text/javascript" src="data.js"></script>
<script type="text/javascript">
console.log(data_json);
const employeeCount = data_json...

Modifying JSON

JSON retrieved from a JSON feed is always going to be read-only; as such, data feeds do not provide functionality to modify their data from unverified sources. There are many cases where we would want to ingest the data from an external data feed, and then modify that content as per our requirements. An example is a company that is using a data feed that is being supplied by a data vendor, but the data that is being provided is a lot more than the company requires. In such cases, rather than using the whole feed, the company would only extract a part of it, perform certain operations to modify it as per their requirements, and reuse the new JSON object. Let us take our employee JSON feed.

Assume that the name of the company was different during different periods. We want to group the employees by company name, which is based on when they joined. Employees who...

Summary

This chapter addressed the core concepts of how to handle static JSON feeds. We began by importing an external JSON object into our HTML file, and looped through the complex array of objects to parse and extract the required data. We used the while and for loops to loop through the array and used conditions to target our search. We completed this chapter by locally modifying the existing JSON feed and adding a new property, the employee object. Now that we have mastered accessing JSON from a static file, it is time for us to make some asynchronous calls to fetch some active JSON over HTTP.

Left arrow icon Right arrow icon

Key benefits

  • Use JSON with trending technologies like Angular, Hapi.js, MongoDB, Kafka, and Socket.io
  • Debug, validate, and format JSON using developer toolkits, JSONLint, and JSON Editor Online
  • Explore other JSON formats like GeoJSON, JSON-LD, BSON, and MessagePack

Description

JSON is an established and standard format used to exchange data. This book shows how JSON plays different roles in full web development through examples. By the end of this book, you'll have a new perspective on providing solutions for your applications and handling their complexities. After establishing a strong basic foundation with JSON, you'll learn to build frontend apps by creating a carousel. Next, you'll learn to implement JSON with Angular 5, Node.js, template embedding, and composer.json in PHP. This book will also help you implement Hapi.js (known for its JSON-configurable architecture) for server-side scripting. You'll learn to implement JSON for real-time apps using Kafka, as well as how to implement JSON for a task runner, and for MongoDB BSON storage. The book ends with some case studies on JSON formats to help you sharpen your creativity by exploring futuristic JSON implementations. By the end of the book, you'll be up and running with all the essential features of JSON and JavaScript and able to build fast, scalable, and efficient web applications.

Who is this book for?

If you’re a web developer with a basic understanding of JavaScript and want to write JSON data, integrate it with RESTful APIs to create faster and scalable applications, this book is for you.

What you will learn

  • Use JSON to store metadata for dependency managers, package managers, configuration managers, and metadata stores
  • Handle asynchronous behavior in applications using callbacks, promises, generators, and async-await functions
  • Use JSON for Angular 5, Node.js, Gulp.js, and Hapi.js
  • Implement JSON as BSON in MongoDB
  • Make use of JSON in developing automation scripts
  • Implement JSON for realtime using socket.io and distributed systems using Kafka

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 23, 2018
Length: 226 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788628761
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Apr 23, 2018
Length: 226 pages
Edition : 2nd
Language : English
ISBN-13 : 9781788628761
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 125.97
JavaScript and JSON Essentials
$32.99
Building Enterprise JavaScript Applications
$48.99
Mastering The Faster Web with PHP, MySQL, and JavaScript
$43.99
Total $ 125.97 Stars icon

Table of Contents

13 Chapters
Getting Started with JSON Chevron down icon Chevron up icon
The JSON Structures Chevron down icon Chevron up icon
AJAX Requests with JSON Chevron down icon Chevron up icon
Cross-Domain Asynchronous Requests Chevron down icon Chevron up icon
Debugging JSON Chevron down icon Chevron up icon
Building the Carousel Application Chevron down icon Chevron up icon
Alternate Implementations of JSON Chevron down icon Chevron up icon
Introduction to hapi.js Chevron down icon Chevron up icon
Storing JSON Documents in MongoDB Chevron down icon Chevron up icon
Configuring the Task Runner Using JSON Chevron down icon Chevron up icon
JSON for Real-Time and Distributed Data Chevron down icon Chevron up icon
Case Studies in JSON Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(2 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
松岡孝明 Mar 22, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
取り扱っている店の対応がとても親切でした。
Amazon Verified review Amazon
Darwin Alphons Jose Jul 12, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Well explained and written in a simple language, easy to learn and understand.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.