How to handle big integer numbers in JSON response in Javascript
<p>I am developing a web application using Javascript &amp; ExtJS framework.</p>

<p>I need to find a generic solution to following problem -</p>

<p>In my application to bring data for a Employee i give call to server api which gives me json response of the Employee data -</p>

<p>SERVER RESPONSE : {"id":10765432100123456789,"id_str":"10765432100123456789", "name" : "Employee1"}</p>

<p>Now on client side i am using ExtJS ajax call which gives call to server and gives the response by converting the response text to an object.</p>

<p>But when i inspect the object then i noticed that value of id key is changed to a different number and value of id_str key remains same.</p>

<p>When i tried to find root cause for this then i came to know about javascript number restriction(Javascript supports at most 53 bits for integer).</p>

<p>Now in my complete application i am using id key to refer employee id. Now i dont want to go to each place and change code to refer id_str for id value.</p>

<p>Note - In my application Employee is one object that i have refered but there are around 20+ object for which i have written code on the id key.</p>

<p>Can some one please guide me what is the best possible solution to handle this kind of scenario.</p>

<p>I am thinking of overriding the JSON.parse(ExtJS internally uses this function to conver json string to an object) function in following way -</p>

<pre><code>var oldFN = JSON.parse;


JSON.parse = function(){
    var jsonStrParam = arguments[0];
    //TODO Read jsonStrParam and write custom logic to convert id integer values to string values 
    var reviverFuncParam = null;
    if(arguments.length == 2)
        reviverFuncParam = arguments[1];
    return oldFN(jsonStrParam,reviverFuncParam);  
}
</code></pre>

<p>In my above approach i have to write code to convert id integer values to string values and then give it to parse function.</p>

<p>I think this will cause performance issues as i have parse the string and iterate over it and change integer values of each key to string values.</p>

<p>Can someone help to figure out what is the best solution that i need to write to take care of big integer numbers at javascript side.</p>

<p><strong>Whether this should be handled at client(browser javascript) side or server side(Java DAO layer) ?</strong></p>