Infimyst Infimyst - 14 days ago 7
Javascript Question

How to Ignore numbers in javascript and json string?

var jsonJSON = UrlFetchApp.fetch("https://wowtoken.info/snapshot.json");
var json = Utilities.jsonParse(jsonJSON.getContentText());

var max24 = json.NA.formatted.24max;


I'm sure my code is sloppy but, I'm getting "Missing ; before statement." from the bottom line. It goes away when I remove the '24', but the source itself has '24max'.

Is there a way to have javascript ignore the 24 after the period? Or are the top two lines of code wrong?

Thanks!

Answer

Instead of removing the numbers in front of the object names during parsing, you can also access the object's property like you would access an array element like so.

json.NA.formatted["24max"]

JavaScript variables must begin with a letter, $ or _. That is the reason why you are getting an error instead.