Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

ParseJson truncates large integer values


I am working on a video streaming channel application which retrieves video metadata from a web service in JSON format. The retrieved JSON data contain video assets' original upload time in milliseconds since Epoch. For instance, a video file was uploaded on "02/28/2013 20:41:44" (1362112904015 Epoch in milliseconds), the retrieved JSON data would look like:

"url": "", "upload_time": 1362112904015, ...

I used a simple BrightScript code to parse the JSON result:
getVideoRequest = CreateObject("roUrlTransfer")
response = ParseJson(getVideoRequest.GetToString())

The parsed "upload_time" is truncated to 608271183 (04/10/1989 21:13:03) from its original 1362112904015. Obviously, the ParseJson() can't properly handle larger than 4-byte integer values.

Is there a way to instruct ParseJson() function to use DOUBLE's to store numbers that are larger than 4-byte integers? Or, are there better BrightScript JSON parsers out there?

0 Kudos
Level 10

Re: ParseJson truncates large integer values

I've run into this before as well. My solution was to use RegEx to convert the values to strings before parsing, then do the conversion in BrightScript:

regex = CreateObject("roRegex", Chr(34) + "upload_time" + Chr(34) + ":\s([0-9]+),", "i")
json = regex.ReplaceAll(json, Chr(34) + "upload_time" + Chr(34) + ": " + Chr(34) + "\1" + Chr(34) + ",")

This can be slow on larger JSON strings, but, while obviously not ideal, it seems to work well otherwise.

You may need to modify the spacing around the colon, depending on how your JSON is formatted. I could have accounted for it automatically in the regex, but I'm too lazy.. Smiley Tongue
My Channels: - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Roku Employee
Roku Employee

Re: ParseJson truncates large integer values

I filed a bug on this last week as Brightcoves's JSON has this issue. A fix of some kind is in the works, although it might not be for a while. In the meantime, Regex to fix the issue or switching to XML are your best bets, some APIs like Brightcove have this as an option, appending &output=mrss or &output=rss to your url will give you an xml formatted string you can work with.

- Joel
0 Kudos