Reputation: 269
When I pass this string to JSON.parse it doesn't work, but if I remove the leading zeros on "000634" it does. Does anyone know why this is? Thanks in advance.
This does not work:
var str = '[["first", "last", "XU10060282", "Dept", 000634, "Position", 156689]]';
var dataArray = JSON.parse(str);
console.log(dataArray);
This does work:
var str = '[["first", "last", "XU10060282", "Dept", 1000634, "Position", 156689]]';
var dataArray = JSON.parse(str);
console.log(dataArray);
`
Upvotes: 1
Views: 955
Reputation: 3254
If you don't need to treat it as the number 634, wrapping the value in quotes also works:
var str = '[["first", "last", "XU10060282", "Dept", "000634", "Position", 156689]]';
Upvotes: 1