Detecting if a Property of an Object is an Object

I'm going to use JSON to stringify the value of a property of an object in order to store it as a Tag on Google Calendar through Google Apps Script. The value is actually a double-nested Object (see extraAttributes in myObject).

I have an Object that is built like the following:

var myObject = {
  "location": "somwehere",
  "date": new Date(),
  "numSomething": 20,
  "extraAttributes": {"used": true, "interval": 60, "internals": {"timer": 10, "visible": false} }

I tried to make it pretty and readable... anyway: myObject actually has anywhere from 20-40 properties, some of which are nested Objects. So here's the question:

Is there a way to notify if the value of a property in an Object is an object itself (would extra levels of nesting be an issue for this detection?)? The reasoning behind this is that I don't know how JSON.stringify and JSON.parse will affect the other data (I've tested it on that one particular value of type Object and it worked fine), and also that I don't know how much of a performance impact that those two functions would have on my script if the properties being stored reach 20-40.

I would rather do a check to see if the value is an Object and stringify only that (would that also be inefficient?). Feel free to lecture me on Objects and nesting if this would cause major problems in the future ;)


All Javascript values, except functions and undefined, can be serialized as JSON.

To answer your question, see the typeof operator.

Another way to check if something is an object instead of using typeof (which can be misleading in some cases — for example typeof [] === 'object') is to use the Object constructor:

var foo = { id: 1 };
var bar = 'string';
console.log(foo === Object(foo)) // true
console.log(bar === Object(bar)) // false

Need Your Help

How can I create visual studio 2012 template from Office App template?

visual-studio-2013 visual-studio-templates

How can I create my custom visual studio template based on Office App template?

RSS items order, does it matter?

java xml language-agnostic rss rome

I created an RSS feed with Java Rome lib. The project is near the end. But I found strange behavior in some RSS clients.