I am facing an issue with my Apps Script Web App where JSON data is being manipulated when I try to parse it. Specifically, keys with leading zeros are being altered (e.g "0123" becomes "123") during the JSON.parse() function call. It seems like the function is interpreting my string as an integer but still treating it as a string. Can anyone confirm if this behavior is expected?
To demonstrate the problem, consider the following script:
function jsontest() {
var json = '{"0123":"foo", "bar":"0123", "foobar":123}';
var test = JSON.parse(json);
var check = ("0123" in test);
var check2 = ("123" in test);
Logger.log(test);
Logger.log(JSON.stringify(test));
Logger.log(check);
Logger.log(check2);
}
The result logged is as follows:
[17-06-07 15:22:56:241 CDT] {123=foo, bar=0123, foobar=123}
[17-06-07 15:22:56:241 CDT] {"123":"foo","bar":"0123","foobar":123}
[17-06-07 15:22:56:242 CDT] false
[17-06-07 15:22:56:243 CDT] true