Book Image

JavaScript and JSON Essentials - Second Edition

By : Bruno Joseph D'mello, Sai S Sriparasa
Book Image

JavaScript and JSON Essentials - Second Edition

By: Bruno Joseph D'mello, Sai S Sriparasa

Overview of this book

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.
Table of Contents (20 chapters)
Title Page
Copyright and Credits
Dedication
Packt Upsell
Contributors
Preface
Index

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.

Note

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",
    "birth_date" : "1980-09-02",
    "first_name" : "Georgi",
    "last_name" : "Facello",
    "gender" : "M",
    "hire_date" : ...