I am creating this JSON object
{
"attachment": {
"type": "template",
"payload": {
"template_type": "generic",
"image_aspect_ratio": "square"
"elements": [
new CreateBallon(results[rand])
]
}
}
}
I want to set the image_aspect_ratio in only if elements[0].someProp is present.
How can I do that?
Let's clear what
JSONis. It is a textual notation for data. If you do anything with the object that involves code ofJavascriptdon't call itJSONso, The object you're talking about is not aJSONbut aJavaScriptobject created via object literal notation.Now to answer your query, you can't refer to
thisobject before you've fully initialized that object. So what you can do is initialize your object with some default value and then you should be able to edit any property based on the properties from the same object. Something likeNow you can update your object like