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 ;)
JSON.stringify-ed are the values that are Objects. So anything that is a String, Integer, Date, etc. can just be tagged normally. The Object needs to be stringified, but I didn't want to do "screw it, stringify everything", I wanted to only stringify the values that needed it to be tagged correctly. Does that make sense? In the end, I completely forgot abouttypeof, and will be using that to accomplish the goal :)myObjectabove) into Tags on Google Calendar Events. The Tags can be pretty much anything except Objects, functions, etc. 90% of the data inmyObjectcan just be tagged normally, but if I want to retain the data that is stored in a nested object (extraAttributesabove), then I need to stringify it. I wanted to avoid stringifying everything, so I wanted to check to see if thetypeof extraAttributes === 'object', so it can be serialized and tagged.typeof null === object; // true