What is the type of the key in this JSON object {yourVariable: "nothing yet"} What is the type of the key in this JSON object {yourVariable: "nothing yet"} json json

What is the type of the key in this JSON object {yourVariable: "nothing yet"}


All object keys are strings with quotes or without quotes. Try this way to see it. May be you are confused with console print because console print it without quotes and we usually write with quotes.

var jsonObj = {person:"me","age":"30", 123:"123"};Object.keys(jsonObj).forEach(function(key){   console.log(typeof key)});


I have a slightly different take on this question which does not invalidate the comments or answer that you received, but is worth considering.

Because you are talking about JSON, there is no intrinsic datatype in your example. As stated on the JSON.org page:

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.

The point is, that there is a difference between JSON, which is a representation of javascript objects, arrays etc., and variables of those types in javascript.

If you remind yourself that JSON is a form of serialization it makes a lot more sense. Javascript objects for example, can include functions, but a javascript function is not a portable thing, so in rendering some JSON from a javascript object, it is up to the language creating the JSON to do whatever it it needs to in order to convert the data it needs to represent, and that may include simplification and in many cases removal of elements that are incompatible JSON.

The other thing to keep in mind, is that all modern languages have functions or libraries that can parse JSON and turn them into variables or objects that work in those languages. In doing so, they have arguments that can completely change the way the JSON is converted back into instance variables.

For example, in PHP you can choose to have the JSON create one or more PHP objects, or an array of php variables.

In summary, JSON doesn't have variables with datatypes at all. It is a representation of data, that is portable across languages, but the languages must decode the JSON and create objects or variables that are valid in their own runtime.