Javascript JSON parse object, one object property undefined, throwing no errors

I have an extremely unique problem; I’m parsing a JSON string back into an array of objects after being passed from PHP via an xmlhttprequest. My web app does this repeatedly with the result of several different sqlsrv_query’s but one query in particular has become very problematic: The id value is not consistent. What I mean by this is that if I output the JSON string before parsing, the id value is an int, but after JSON parsing it is undefined. The rest of the values are fine, it is only the id(which is the only int). Furthermore, after parsing, if I convert the object back into a JSON string the int value is restored. If I attempt to call the property like so ‘object.prop’ it returns undefined. I have checked, double checked, and triple checked that there are no typos. I have console.logged the entire array of objects(at various points throughout execution) with the same result. I could find nothing on SO, google, or here that would explain this behavior, can you?

Here are some code snippets.

Inside the xmlhttprequest callback function:

var result1 = decodeURIComponent(xmlhttp.responseText);

console.log(result1); <-- * SEE OUTPUT BELOW *

if('<br') === -1) {
    this.result = JSON.parse(result1);

} else {

output:  [{"sheet_id":4054,"o_number":1,"o_description"...

After being parsed, the object is passed to another object:

if(!result) {
    //var error = new ErrorLog();
} else {
    console.log(result); <-- * SEE OUTPUT BELOW *

output: [Object, Object, Object, Object, Object]
          0: Object
             prop1: someValue
             prop2: someOtherValue
             sheet_id: undefined

To keep the Trolls at bay, let me reiterate the extent to which I have tested this scenario:

The same results are produced in Chrome and IE11. I have tried performing the same query for multiple different records, but the same thing happens. The multitude of other queries(different queries) returning a mix of int’s and strings do not have this problem. I have tried closing the browser and reopening in case it was some sort of strange temporary anomaly.

I’ve never posted on here before because I almost always find an answer to a question with some research but this is beyond my ability to resolve so I turn to the good people of SO for assistance, any solution, insight, or idea of where to look for an answer would be greatly appreciated.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s