Link to home
Start Free TrialLog in
Avatar of aaron248
aaron248Flag for United States of America

asked on

Empty Values in a JavaScript JSON Object

There will be some javascript on every page of my site that gets a JSON object embedded into a <script/> tag in my html. Sometimes the JSON object will look like this:

var pageData = {
		"navigation" : {
			"pageName" : "anypage-123", 
			"pageSite" : "anysite.com",
			"pageType" : "any",
			"sale-price" : 27.50
                        "price" : 55.00
		}
	};

Open in new window


other times there will be no "sale-price". Is it better to leave the "sale-price" out altogether or can I do something like this:

var pageData = {
		"navigation" : {
			"pageName" : "anypage-123", 
			"pageSite" : "anysite.com",
			"pageType" : "any",
			"sale-price" : null,
                        "price" : "55.00"
		}
	};

Open in new window


What's the best practice? Using the keyword "null" or leaving it blank and just have the comma?

Thanks in advance!
Aaron
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial