tornir: A friendly looking leopard.taken from an online icon maker. (Default)
Tornir the Leopardess ([personal profile] tornir) wrote in [community profile] javascript 2019-06-10 04:11 pm (UTC)

I think scope is biting me in multiple places here, yes. :(
Looking at rearranging things to avoid losing it.


The JSON appeared to be working so I compared the two versions (with explicit typo in the new version, just to check it was doing what it looked to be doing):
	var myObj_2= {First_Image_x_1, First_Image_y_1, Second_Image_x_1, Second_Image_y_1};
	var myJSON_2= JSON.stringify(myObj_2);
	document.getElementById("test4").innerHTML= "Old JSON: "+myJSON_2;

	var myObj_9= {
		First_ImaGe_x_1: First_Image_x_1, First_Image_y_1: First_Image_y_1,
		Second_Image_x_1: Second_Image_x_1, Second_Image_y_1: Second_Image_y_1
	};
	var myJSON_9= JSON.stringify(myObj_9);
	document.getElementById("test5").innerHTML= "New JSON: "+myJSON_9;


The two versions output as:

Old JSON: {"First_Image_x_1":49,"First_Image_y_1":50,"Second_Image_x_1":34,"Second_Image_y_1":34}

New JSON: {"First_ImaGe_x_1":49,"First_Image_y_1":50,"Second_Image_x_1":34,"Second_Image_y_1":34}

...so it looks like you can get away without explicit declaration* before stringification despite JSON canon saying it has to be done your way with the name/value pair.

*In FF67 & Chrome73

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting