Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2694

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T07:47:07+00:00 2024-11-26T07:47:07+00:00

Day 29 of 30 of JavaScript

  • 61k

Hey reader👋 Hope you are doing well😊
In the last post we have talked about interfaces of DOM. In this post we are going to discuss about JSON.
So let's get started🔥

What is JavaScript JSON?

JSON stands for Java*Script **Object **N*otation. It is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. In simple words we can say that it is a text format for storing and transporting data.
Example -:
Image description
Here we have an object with three properties.
JSON is used to send data between computers.
JSON is built on two structures:

  1. A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  2. An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

Why JSON?

We know that whenever we declare a variable and assign a value to it, it’s not the variable that holds the value but rather the variable just holds an address in the memory where the initialized value is stored.
Suppose we have var age=22 so here age holds the memory location where 22 is stored. Now suppose you have to transfer data now what you will do is you will give your computer memory in order to transfer data because your data is stored in memory and you don't have any other way apart from it. But giving away complete memory is risky and problematic. So how can we transfer the data🤔.
This problem is resolved by JSON. JSON serializes the data and converts it into a human-readable and understandable format, which also makes it transferal and to be able to communicate.
In summary, JSON solves the data transfer problem by converting data into a standardized, text-based format that is easily transferable between systems and across different platforms. This ensures that data can be accurately and efficiently communicated without relying on machine-specific memory representations.

Advantages of JSON

  1. Human-Readable: JSON is easy for humans to read and write.

  2. Interoperable: JSON is language-independent but uses conventions that are familiar to programmers of the C family of languages (including C, C++, C#, Java, JavaScript, Perl, Python, and many others).

  3. Lightweight: JSON is less verbose than XML, making it a more efficient format for data interchange.

  4. Easy to Parse: JSON can be easily parsed by machines, and most programming languages provide libraries or functions to parse and generate JSON.

JSON Syntax Rules

JSON syntax is derived from JavaScript object notation syntax:

  • Data is in name/value pairs. Example -: "name:"Akshat"

  • Data is separated by commas. Example -: "name:"Akshat", "age":22

  • Curly braces hold objects. Example -: let details={"name:"Akshat", "age":22}

  • Square brackets hold arrays. Example -: let details={"name:"Akshat", "age":22,"ids":[12345,6678]}
    JSON Objects
    A JSON object is a collection of key/value pairs. The keys are strings, and the values can be strings, numbers, objects, arrays, true, false, or null.
    JSON Arrays
    A JSON array is an ordered collection of values. The values can be strings, numbers, objects, arrays, true, false, or null.
    Image description
    Here we have an object that holds an array Avengers in which each value is detail object of an avenger.
    To access name of first avenger-:
    Avengers[0].Name
    The file type for JSON files is “.json”.

Convert a JSON Text to a JavaScript Object

We will be using the JSON.parse() method to convert the JSON text to a JavaScript Object.
Image description

When using the JSON.parse() on a JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object.
Image description
Date objects are not allowed in JSON.If you need to include a date, write it as a string.
Image description
Functions are not allowed in JSON.If you need to include a function, write it as a string.
Image description

JSON.stringify()

Convert a JavaScript object into a string with JSON.stringify().
Image description

Storing Data

JSON makes it possible to store JavaScript objects as text.
Image description
The localStorage.setItem() method is used to store this JSON string in the browser's local storage with the key “testJSON”. This allows the data to persist across browser sessions.
To retrieve the stored data, the localStorage.getItem() method is called with the key “testJSON”, returning the JSON string previously stored. This string is then parsed back into a JavaScript object using the JSON.parse() method, and the resulting object is assigned to the variable obj.

So this is it for this blog I hope you have understood it well. Please feel free to add if I have missed something.
Don't forget to follow me.
Thankyou🩵

beginnersjavascripttutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.