JavaScript Top 5 Most useful JSON Example

JavaScript Top 5 Most useful JSON Example

Today, We want to share with you JavaScript Top 5 Most useful JSON Example.
In this post we will show you JSON Most useful Top 5 Example using JavaScript, hear for JavaScript Object Notation (JSON) we will give you demo and example for implement.
In this post, we will learn about An Introduction to JavaScript Object Notation (JSON) in JavaScript with an example.

JSON is a one type of format for storing(light weight data) and transporting data.
it’s used when data is sent from a (Serever side to client side) server to a web page(all data sent).

Read Also:  Angular 9/8 Material Input Box Examples

JSON Simple full form of [JavaScript-Object-Notation].

Example 1 :

How to get the key value in JSON object?

 var JsonDataObject= { "progname1":"Laravel", "progname2":"PHP", "progname3":"JSON", "progname4":"jQuery", "progname5":"Magento" };

	//all read key using for loop
	for (var key in JsonDataObject) 

<h3>Output - Console.log:</h3>

Example 2 : JavaScript JSON

how to get json key and value in javascript?

//used to jquery json parser

var JsonDataObject = $.parseJSON('{ "progname1":"Laravel", "progname2":"PHP", "progname3":"JSON", "progname4":"jQuery", "progname5":"Magento" }');

//used to json parser
var JsonDataObject = JSON.parse('{ "progname1":"Laravel", "progname2":"PHP", "progname3":"JSON", "progname4":"jQuery", "progname5":"Magento" }');

Example 3 : simple json example

Get json value from response

var response_data = JSON.parse('{"ui_id":"98256cd-d692-k965-85978-0625457DFr"}');
response_data.ui_id ; //# =&gt; 98256cd-d692-k965-85978-0625457DFr

Example 4 : json examples

Example : Adding/removing items from JSON data with JQuery

Simple JSON Data records

var data = {products: [
    {product_id: "1", product_name: "Snatch", product_cat: "crime"},
    {product_id: "2", product_name: "pakainfo of Eastwick", product_cat: "comedy"},
    {product_id: "3", product_name: "computer", product_cat: "action"},
    {product_id: "4", product_name: "Ordinary People", product_cat: "drama"},
    {product_id: "5", product_name: "Billy Elliot", product_cat: "lp"},
    {product_id: "6", product_name: "Toy Story", product_cat: "Mobile"}

New Adding an record from JSON:

    {product_id: "7", product_name: "Douglas Adams", product_cat: "comedy"}

Form Removing an record from JSON:

data.products.splice(1, 3); 
// Removes 3 products starting with the 2nd,
// ("pakainfo of Eastwick", "computer", "Ordinary People")

New Adding in the middle record from JSON:

data.products.splice(2, 0,
    {product_id: "7", product_name: "Douglas Adams", product_cat: "comedy"}

Example of JSON-Data

Example 5 :1 – JSON Example

	{"postname":"er", "salary":"25000"},
	{"postname":"dr", "salary":"30000"},
	{"postname":"tr", "salary":"58222"}

2 – JSON Objects Example

{"postname":"er", "salary":"Doe"} 

3 – JSON Arrays Example

    {"postname":"er", "salary":"98522"},
    {"postname":"dr", "salary":"10000"},
    {"postname":"tr", "salary":"24550"}

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Simple Multi Step Form with validation Using AngularJS
  2. Read Also:  How to Dynamic Populate Values in One HTML Dropdown List With Another Using Simple Javascript PHP?
  3. Read Also:  PHP stdClass object Array Examples with scripts
  4. Read Also:  What is the difference between Java and JavaScript?
  5. Read Also:  One to Many Relationship in Laravel 5.7 Eloquent
  6. Read Also:  Delete All Files from Folder with PHP
  7. Read Also:  Angularjs 6 User Registration and Login Authentication
  8. Read Also:  WordPress Plugin Redirect After Activation
  9. Read Also:  Vuejs Clone Array Example with Demo
  10. Read Also:  Angular 9/8 Material Input Box Examples