I have come across an issue converting a JSON string in R (with either the
package 'rjson' or 'RJSONIO') when big integers are included in the JSON
string.

A simple example of the problem is:

> options(scipen=999)  # To prevent representing the answer in scientific
notation
> json.str <- '{"bigInt":123456789123456789}'  # Sample JSON string with
big integer

Using the RJSONIO package:
> fromJSON(json.str)  # From package 'RJSONIO'
            bigInt
123456789123456784

Using the rjson package:
> fromJSON(json.str)  # From package 'rjson'
$bigInt
[1] 123456789123456784

Notice the difference in the last digit (4 vs. 9).

In my research, I have come across various ways to handle big integers in R
(the 'int64' package, for example), but I don't believe this helps with the
numeric representation/interpretation that occurs inside of the rjson and
RJSONIO packages.

It is not important in my application for numeric nodes in the JSON to be
preserved as a numeric class - if everything came back as a string, that
would be acceptable.  Therefore, I was hoping the 'handler' or 'stringFun'
arguments within the RJSONIO package would allow me to specify a character
representation for all nodes inside the JSON string, such that:
> fromJSON(json.str)
would result in:
$bigInt
[1] "123456789123456789"

However, it looks like the 'stringFun' is only applied to the character
string nodes within the JSON:

>
fromJSON('{"bigInt1":123456789123456789,"bigInt2":"123456789123456789"}',stringFun=function(x)
class(x))
$bigInt1
[1] 123456789123456784

$bigInt2
[1] "character"

I think there might be some promise to the 'handler' object, but I'm having
trouble interpreting how to implement it effectively.

Thank you in advance for any solutions/suggestions/references that you may
be able to provide!
Regards,
Trannon

 ______________________________
Trannon Mosher
Data Modeling Analyst
Clear Capital

	[[alternative HTML version deleted]]

