1. Is the key/property name valid both with/without quotes?

The only time you need to enclose a key in quotes when using Object Literal notation is where the key is a reserved word or contains a special character (if, :, -, etc.). It is worth noting that a key in JSON must be enclosed in double quotes.

  1. If I convert the above object to JSON using var jSonString = JSON.stringify(testObject);, what is the difference between the two (JavaScript obj and JSON)?

JSON is a data interchange format. It's a standard which describes how ordered lists and unordered maps, strings, booleans and numbers can be represented in a string. Just like XML and YAML is a way to pass structured information between languages, JSON is the same. A JavaScript object on the other hand is a physical type. Just like a PHP array, a C++ class/ struct, a JavaScript object is a type internal to JavaScript.

Here's a story. Let's imagine you've purchased some furniture from a store, and you want it delivered. However the only one left in stock is the display model, but you agree to buy it.

In the shop, the chest-of-drawers you've purchased is a living object:

    var chestOfDrawers = {
        color: "red",
        numberOfDrawers: 4
    }

However, you can't send a chest-of-drawers in the post, so you dismantle it (read, stringify it). It’s now useless in terms of furniture. It is now JSON. It’s in flat pack form.

    {"color":"red","numberOfDrawers":4}

When you receive it, you then rebuild the chest-of-drawers (read, parse it). It’s now back in object form.

The reason behind JSON, XML and YAML is to enable data to be transferred between programming languages in a format both participating languages can understand; you can't give PHP or C++ your JavaScript object directly; because each language represents an object differently under-the-hood. However, because we've stringified the object into JSON notation; i.e., a standardised way to represent data, we can transmit the JSON representation of the object to another language (C++, PHP), they can recreate the JavaScript object we had into their own object based on the JSON representation of the object.

It is important to note that JSON cannot represent functions or dates. If you attempt to stringify an object with a function member, the function will be omitted from the JSON representation. A date will be converted to a string;

    JSON.stringify({
        foo: new Date(),
        blah: function () {
            alert('hello');
        }
    }); // Returns the string "{"foo":"2011-11-28T10:21:33.939Z"}"
  1. For parsing a JSON string, is the method below recommended? var javascriptObj = JSON.parse(jSonString);

Yes, but older browsers don't support JSON natively (before Internet Explorer 8). To support these, you should include json2.js.

If you're using jQuery, you can call jQuery.parseJSON(), which will use JSON.parse() under the hood if it's supported and will otherwise fallback to a custom implementation to parse the input.

Answer from Matt on Stack Overflow
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Why convert json to javascript object? Why not use it as is? - JavaScript - The freeCodeCamp Forum
April 23, 2019 - Hello all, I’ve just been introduced to the JSON.parse() function. I may be missing something obvious here but I don’t see why JSON needs to be converted to a JavaScript Object. My confusion is because I am thinking t…
🌐
Koombea
koombea.com › home › json vs. javascript: what is the difference?
JSON Vs. JavaScript: What is the Difference?
November 26, 2024 - JavaScript. JSON is short for JavaScript Object Notation. So is JSON JavaScript? Not exactly. JSON is a data format that is independent of any programming language, although it is derived from JavaScript.
Discussions

JavaScript object vs. JSON - Stack Overflow
It's a standard which describes how ordered lists and unordered maps, strings, booleans and numbers can be represented in a string. Just like XML and YAML is a way to pass structured information between languages, JSON is the same. A JavaScript object on the other hand is a physical type. More on stackoverflow.com
🌐 stackoverflow.com
What is JSON and what does it have to do with Javascript?
I notice it's an acronym "JavaScript Object Notation" so obviously has lots to do with Javascript, but apparently it's also " a language-independent data format." (whatever that means). It means that the syntax of JSON is based on the way you construct objects in JavaScript, but it exists independently from JS. It's a data exchange format. Similar to XML. It's just a way to use text to structure data. JSON isn't a language that really requires proficiency. For one thing, it's not a programming language; it doesn't convey logic. It's just data. And it's quite simple. There are only four data types in JSON: string, number, array, and object. Whether or not you have to be proficient with it to use WebSockets? Technically they aren't directly related. But JSON is an extremely common format to pass data over WebSockets (as well as HTTP endpoints as well). More on reddit.com
🌐 r/learnprogramming
11
0
March 31, 2022
javascript - What is difference between .json and .js file which are used while coding three.js? - Stack Overflow
.json and .js file are used in three.js. They are one of the object's format. what is difference between them? Do they require different loaders to load the object? I was following this three.js e... More on stackoverflow.com
🌐 stackoverflow.com
JSON-LD vs JSON Schema
JSON-LD (JSON Linked Data) is a description of the content of a URL so that search engines don't have to guess the content of the URL. It also contains references to other URLs and a description. It generally describes "Thing"s with their properties as they are defined by schema.org. Like an Event has a Location (which also is a Thing and can be represented by a URL) and a description, …. JSON Schema is a JSON definition of another JSON document, like what DTD (Document Type Definition) is for XML. It describes, which fields are required, if properties are another object, array, string or number and so on. An example for the use of JSON-Schema with Java: If you want to use a JSON-Api and have the JSON-Schema of the objects, then you can generate the classes automatically rather than write them on your own. More on reddit.com
🌐 r/javascript
6
2
July 22, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › json-vs-javascript-object
JSON vs JavaScript Object - GeeksforGeeks
August 5, 2025 - JSON is a lightweight data format for transferring data, while JavaScript Objects are in-program data structures used for manipulation and logic.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON
JSON - JavaScript | MDN
Other differences include allowing only double-quoted strings and no support for undefined or comments. For those who wish to use a more human-friendly configuration format based on JSON, there is JSON5, used by the Babel compiler, and the more commonly used YAML. The same text may represent different values in JavaScript object literals vs.
🌐
Programiz
programiz.com › javascript › json
JavaScript and JSON (with Examples)
Become a certified JavaScript programmer. Try Programiz PRO! ... JSON stands for Javascript Object Notation. JSON is a text-based data format that is used to store and transfer data.
🌐
Appsmith
community.appsmith.com › content › blog › javascript-objects-vs-json-explained-simply
Javascript Objects Vs JSON: Explained Simply | Appsmith Community Portal
March 26, 2024 - Although JSON resembles Javascript object literal syntax, it enforces stricter rules. Property names must be enclosed in double quotes, and they cannot contain comments or functions.
Find elsewhere
Top answer
1 of 5
288
  1. Is the key/property name valid both with/without quotes?

The only time you need to enclose a key in quotes when using Object Literal notation is where the key is a reserved word or contains a special character (if, :, -, etc.). It is worth noting that a key in JSON must be enclosed in double quotes.

  1. If I convert the above object to JSON using var jSonString = JSON.stringify(testObject);, what is the difference between the two (JavaScript obj and JSON)?

JSON is a data interchange format. It's a standard which describes how ordered lists and unordered maps, strings, booleans and numbers can be represented in a string. Just like XML and YAML is a way to pass structured information between languages, JSON is the same. A JavaScript object on the other hand is a physical type. Just like a PHP array, a C++ class/ struct, a JavaScript object is a type internal to JavaScript.

Here's a story. Let's imagine you've purchased some furniture from a store, and you want it delivered. However the only one left in stock is the display model, but you agree to buy it.

In the shop, the chest-of-drawers you've purchased is a living object:

    var chestOfDrawers = {
        color: "red",
        numberOfDrawers: 4
    }

However, you can't send a chest-of-drawers in the post, so you dismantle it (read, stringify it). It’s now useless in terms of furniture. It is now JSON. It’s in flat pack form.

    {"color":"red","numberOfDrawers":4}

When you receive it, you then rebuild the chest-of-drawers (read, parse it). It’s now back in object form.

The reason behind JSON, XML and YAML is to enable data to be transferred between programming languages in a format both participating languages can understand; you can't give PHP or C++ your JavaScript object directly; because each language represents an object differently under-the-hood. However, because we've stringified the object into JSON notation; i.e., a standardised way to represent data, we can transmit the JSON representation of the object to another language (C++, PHP), they can recreate the JavaScript object we had into their own object based on the JSON representation of the object.

It is important to note that JSON cannot represent functions or dates. If you attempt to stringify an object with a function member, the function will be omitted from the JSON representation. A date will be converted to a string;

    JSON.stringify({
        foo: new Date(),
        blah: function () {
            alert('hello');
        }
    }); // Returns the string "{"foo":"2011-11-28T10:21:33.939Z"}"
  1. For parsing a JSON string, is the method below recommended? var javascriptObj = JSON.parse(jSonString);

Yes, but older browsers don't support JSON natively (before Internet Explorer 8). To support these, you should include json2.js.

If you're using jQuery, you can call jQuery.parseJSON(), which will use JSON.parse() under the hood if it's supported and will otherwise fallback to a custom implementation to parse the input.

2 of 5
32

Question 1: When defining object literals in JavaScript, the keys may include quotes or not. There is no difference except that quotes allow you to specify certain keys that would cause the interpreter to fail to parse if you tried them bare. For example, if you wanted a key that was just an exclamation point, you would need quotes:

a = { "!": 1234 } // Valid
a = { !: 1234 } // Syntax error

In most cases though, you can omit the quotes around keys on object literals.

Question 2: JSON is literally a string representation. It is just a string. So, consider this:

var testObject = { hello: "world" }
var jSonString = JSON.stringify(testObject);

Since testObject is a real object, you can call properties on it and do anything else you can do with objects:

testObject.hello => "world"

On the other hand, jsonString is just a string:

jsonString.hello => undefined

Note one other difference: In JSON, all keys must be quoted. That contrasts with object literals, where the quotes can usually be omitted as per my explanation in Q1.

Question 3. You can parse a JSON string by using JSON.parse, and this is generally the best way to do it (if the browser or a framework provides it). You can also just use eval since JSON is valid JavaScript code, but the former method is recommended for a number of reasons (eval has a lot of nasty problems associated with it).

🌐
Reddit
reddit.com › r/learnprogramming › what is json and what does it have to do with javascript?
r/learnprogramming on Reddit: What is JSON and what does it have to do with Javascript?
March 31, 2022 -

Hi! I'm looking to dive back into Javascript after a 10+ year hiatus (learned some during college) in order to build out a basic piece of software using a WebSocket for a lighting control system. I notice that most of it can be done with Javascript, but every now and then there are JSON calls. Looking at JSON's wiki page, I notice it's an acronym "JavaScript Object Notation" so obviously has lots to do with Javascript, but apparently it's also " a language-independent data format." (whatever that means).

Any indications if I'll need to be proficient with JSON to work with the WebSocket? If so, any recommendations for resources to get started? Thank you!

Top answer
1 of 5
4
I notice it's an acronym "JavaScript Object Notation" so obviously has lots to do with Javascript, but apparently it's also " a language-independent data format." (whatever that means). It means that the syntax of JSON is based on the way you construct objects in JavaScript, but it exists independently from JS. It's a data exchange format. Similar to XML. It's just a way to use text to structure data. JSON isn't a language that really requires proficiency. For one thing, it's not a programming language; it doesn't convey logic. It's just data. And it's quite simple. There are only four data types in JSON: string, number, array, and object. Whether or not you have to be proficient with it to use WebSockets? Technically they aren't directly related. But JSON is an extremely common format to pass data over WebSockets (as well as HTTP endpoints as well).
2 of 5
3
JSON came from JavaScript but it has nothing to do with JavaScript anymore. Have you ever used XML before? JSON is basically used for most of the same sorts of things that XML was used for. JSON is basically a handy standard format to use when sending structured data from one program to another, or when saving data to a file, or something like that. That's it. By using JSON instead of making up your own format, you make it easy for anyone to parse. JSON specifies the syntax, but not the semantics. You can decide whatever data you want to put in it. Let's say you wanted to save a list of names to a file. Using JSON, you could do it like this: ["Candace", "Maya", "Ken", "Tobias"] It looks just like you're defining an array in JavaScript, and that's the idea. Let's say you needed names and ages. You could do it like this: [ { "name": "Candace", "age": 44 }, { "name": "Maya", "age": 19 }, { "name": "Ken", "age": 35 }, { "name": "Tobias", "age": 27 } ] Should you learn JSON? Yes, but it's really not that complicated. You could read the documentation in an hour and get the hang of reading and writing JSON in your favorite language in less than a day. Sure, there's more complexity to it sometimes. If you're working with really large amounts of data, people have created all sorts of tools for manipulating large JSON files, or doing queries or transformations. If you ever have a need for those, you can learn them.
🌐
Medium
medium.com › geekculture › json-object-v-javascript-object-f00ae788cc1f
JSON Object v. JavaScript Object. Recently in my job search, I was being… | by Alyssa E Easterly | Geek Culture | Medium
April 6, 2021 - Overall when comparing the two: a JSON object and a JavaScript object, we know that a JSON object is the messenger. JSON is written only as text and is a seamless way to send Javascript data between the browser and server.
🌐
MongoDB
mongodb.com › resources › languages › what-is-json
What Is JSON? | A Beginner’s Guide | MongoDB
JavaScript is a programming language used for building the user interface of a web application, whereas JSON is a data interchange format used for transferring data between front end and back end.
🌐
Quora
quora.com › If-JSON-is-a-JavaScript-thing-why-do-we-use-it-on-other-programming-languages
If JSON is a JavaScript thing, why do we use it on other programming languages? - Quora
Answer (1 of 3): Because it’s now everywhere - JSON is directly translatable to PHP and Python - and back. In other words, you can create an object on the server, turn it into JSON - and use it as an object on the browser. The browser can then manipulate the object, send it back to the server ...
Top answer
1 of 1
2

.json and .js file are used in three.js. They are one of the object's format. what is difference between them?

js extension marks that content of the file should be script following javascript syntax and so is human readable.

json extension marks that content of the file should be tree structure following javascript object syntax (javascript object has nothing to do with 3d objects) and so is human readable. Also this structure is valid for .js extension, in other words any valid json file is also valid js file.

Three js loaders are from the big part file parsers. These loaders does not care about file extension at all. It is ignored. Only important thing for the parser is content of the file.

Do they require different loaders to load the object?

As I know, three.js is able to load multiple kinds of structures. Each kind has each own loader (and loader contain one or more parsers).

The most basic one is JSONLoader. It requires file with specific json structure (data about materials, normals, positions, texture coordinates and more or less, not everything is compulsory).

The example you provided uses BinaryLoader. This binary loader requires two files (as I understand). First file contains json structure with materials and location of other file (so json parser is used to parse this file). Second file contains buffers (data about normals, positions, texture coord...) and is binary file. I have no idea what exact binary structure is used here. You see this is kind of hybrid and if you provide buffer data in json structure, it wont be able to read it.

Last loader I have heard of is fbxloader, which can read results created in blender for example. But Im not sure if this one is working.

In that example .js file for object and for that BinaryLoader is used. But when I do the same means I had used the .js file for my object with BinaryLoader, it did not worked.

I hope this is clear now. BinaryLoader expects two files with json and binary structures. It ignores file name including extension. If you create two files named blablabla.wtf and blabla.omg, but with correct structures inside, it will work. I guess you had one file with correct json structure. This will work with JSONLoader only.

More about file loaders

There are 3 aspects we can talk about. Parsing speed, file size and maintainability. Parsing speed is more important if you want to download more and more data on the run. File size is more important if current size is going to break some limit (that shouldnt or cannot be breaked). Maintainability is more important if you need to change the file content a lot.

Binary formats are better for file size and parsing speed. But major browsers use gzip/bzip compression which makes json files almost same size as binary. Maintainability should always be the most important aspect. Json structures are very easy to maintain and debug. fbx or other binary formats are better for big and robust projects with lot of assets.

EDIT:

Im afraid I will have to explain a little bit more...

Lets talk about entire concept for a while. Lets say we have an empty world and we would like to put two models inside, simple cube and some animal.

There are three basic ways to do that. Generate it procedurally, use external data or hybrid (part is procedural, part is external data).

Procedural or hybrid might be for example sea with waves.

Procedural generation is done by some algorithm in the program, while external data must be inserted with some program tool, the loader.

Examine the cube and the animal now. Cube is just simple object made of 6 planes. It can't move, breathe, eat, anything. It just exists. On the other side, animal is much more complicated, it wont just stay in the middle and does not move. All these things will be part of the external data (file or files).

I provided two very different things, but it is important to know even the simplest things are complicated in 3D and can be manipulated different ways. For example what color does that cube has? Does each plane have same color? Is it shiny? Can it reflect?

The main thing is what kind of description can loader accept, read and understand. First you must know everything about the loader and then you can create an object.

This is example what structures can JSONLoader accept: https://github.com/mrdoob/three.js/wiki/JSON-Geometry-format-4 https://github.com/mrdoob/three.js/wiki/JSON-Material-format-4

For example, if "metadata" contains "type": "Geometry", then loader will look for "indices", "vertices", "normals" and "uvs". Some parts might be optional, like "uvs". Simple cube can be assembled only from vertices, but it is probably not what this particular loader knows and even if your structure does make sence, it might be unknown for the loader.

Binary loaders are very different, because there are no words in binary code, just 0 and 1. So you need a lot of metadata to specify what exactly is inside. Metadata can be part of the same file or some different file. But it again depends where the loader will look for them.

Could you please tell me, what do mean by JSON structure?

Usually I mean the structure readable with specific loader.

I am guessing that it might be the content that .js file has.

In case of example you provided, yes in this file is json structure: http://mrdoob.github.io/three.js/examples/obj/veyron/VeyronNoUv_bin.js

.js file content is different when it is used with BinaryLoader as you have mentioned it contains buffers.

Be more precise, it does not contain buffers. It contains keyword "buffers": leading us to file "VeyronNoUv_bin.bin", where are data for buffers. Also it contains additional important informations related to "VeyronNoUv_bin.bin" (how many vertices, normals etc.). So you could say, .js file content contains metadata for itself and metadata for related binary file.

Data about vertices, normals etc. are later loaded into buffers in the program, this is why they choose keyword buffers. More precise identification would be dataForBuffers.

And when it is used with JSONLoader it contains long list of vertices. Am I understanding right?

Exactly! When JSONLoader is used, long list of vertices etc. is readed and then loaded into buffers.

🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › software development
What is JSON, and how to use it in JavaScript | Pluralsight
May 19, 2025 - JSON supports a limited set of data types that are simple yet flexible for representing structured data. These include: ... In JavaScript, you can create JSON objects by defining a JavaScript object with the appropriate structure and then converting it to JSON using the JSON.stringify() method.
🌐
SnapLogic
snaplogic.com › home › json (javascript object notation) – defintion & overivew
JSON (JavaScript Object Notation) - Defintion & Overivew
August 25, 2023 - JSON was initially developed as a subset of JavaScript, however, it is in fact language-independent. JSON also uses many conventions common to the C-family of languages.
🌐
Medium
medium.com › @ExplosionPills › json-is-not-javascript-5de833fbe49c
JSON Is not JavaScript. (and JavaScript is not JSON) | by Andrew Crites | Medium
March 29, 2017 - JSON Is not JavaScript (and JavaScript is not JSON) You don’t have to spend much time on Stackoverflow before you find someone saying something like I have JSON like {key: value}. How do I access …
🌐
Oracle
oracle.com › ai database
Here’s Why JSON Rules the Web
April 4, 2024 - JSON's language-independent nature makes it an ideal format for exchanging data across different programming languages and platforms. For instance, an application written in Java can easily send JSON data to a Python application. Or a mobile app written in JavaScript can use JSON to communicate with a back-end server written in PHP.
🌐
TheServerSide
theserverside.com › definition › JSON-Javascript-Object-Notation
What is JSON? - Definition from TechTarget.com
JSON (JavaScript Object Notation) is a text-based, human-readable data interchange format used to exchange data between web clients and web servers. The format defines a set of structuring rules for the representation of structured data.
🌐
JSON
json.org
JSON
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition - December 1999.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
JSON is a text-based data format following JavaScript object syntax. It represents structured data as a string, which is useful when you want to transmit data across a network. Even though it closely resembles JavaScript object literal syntax, it can be used independently from JavaScript.
🌐
W3Schools
w3schools.com › js › js_json.asp
JavaScript JSON
When storing data, the data has to be a certain format, and regardless of where you choose to store it, text is always one of the legal formats. JSON makes it possible to store JavaScript objects as text.