Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between JSON object and Javascript object #14

Open
HSM009 opened this issue Apr 27, 2023 · 1 comment
Open

Difference between JSON object and Javascript object #14

HSM009 opened this issue Apr 27, 2023 · 1 comment

Comments

@HSM009
Copy link

HSM009 commented Apr 27, 2023

Please update the readme

Javascript Object
const detail = { "name": "Vipin", "age": 21 };

JSON Object
const detail = '{ "name": "Vipin", "age": 21 }';

JSON object is string. After parse they are separated into key/value.

@GRAUF
Copy link

GRAUF commented Feb 16, 2024

In JavaScript, there's a distinction between a JavaScript object and a JSON object, although they may seem similar.

  1. JavaScript Object:

    const detail = { "name": "Vipin", "age": 21 };

    Here, detail is a JavaScript object. It's defined using object literal notation, denoted by curly braces {}. This object has two properties: "name" with the value "Vipin" and "age" with the value 21. This is a native JavaScript object.

  2. JSON Object:

    const detail = '{ "name": "Vipin", "age": 21 }';

    Here, detail appears to be a JSON-like string. JSON stands for JavaScript Object Notation, and it's a lightweight data-interchange format. The provided example, however, is a string literal, not a JSON object. It's important to note that JSON is primarily a data format used for exchanging data between a server and a client, and it's a subset of JavaScript object literal notation.

To use the JSON data, you need to parse it:

const detail = '{ "name": "Vipin", "age": 21 }';
const parsedDetail = JSON.parse(detail);

After parsing, parsedDetail becomes a JavaScript object equivalent to { "name": "Vipin", "age": 21 }.

In summary, while JavaScript objects and JSON objects share some similarities, they are not the same. JSON is a text format that is completely language-independent but uses conventions familiar to programmers of the C-family of languages, while JavaScript objects are native data structures in JavaScript itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants