lmsilva
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2012
01:12 PM
Can brightscript parse json?
Dear all,
I have been looking in the docs and I believe the answer to my question is NO but I wanted to make sure...
Can brightscript parse json? (natively, without having to resort to regex)?
Thank you,
Luis
I have been looking in the docs and I believe the answer to my question is NO but I wanted to make sure...
Can brightscript parse json? (natively, without having to resort to regex)?
Thank you,
Luis
8 REPLIES 8


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2012
01:24 PM
Re: Can brightscript parse json?
The answer is no. There has been a lot of discussion on this topic in the past. Often times, a quick search of the forum will get you an answer faster than starting a new thread...
search.php?st=0&sk=t&sd=d&sr=posts&keywords=json&fid%5B%5D=34
search.php?st=0&sk=t&sd=d&sr=posts&keywords=json&fid%5B%5D=34
lmsilva
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2012
03:21 PM
Re: Can brightscript parse json?
Thank you, my bad, you are right, I should have done a search on the forum but I only focused on the docs...
I haven't been having a lot of luck finding stuff on the forum so that's why I didn't even bother to search on it - I apologize for wasting your time!
I haven't been having a lot of luck finding stuff on the forum so that's why I didn't even bother to search on it - I apologize for wasting your time!
kbenson
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2012
10:00 AM
Re: Can brightscript parse json?
Ther eis no JSON parser in the core BrightScript language, but depending on the size of the JSON, and whether it needs to be completely reversible, there are libraries to help: https://github.com/rokudev/librokudev/tree/master/source/librokudev/source/rokudev_src.
A few things to note:
It's slow, particularly so with large chunks of JSON.
Key names with spaces will be changed to have underscores, as BrightScript doesn't allow spaces in associative array key names.
That said, you may find it sufficient for your needs.
A few things to note:
It's slow, particularly so with large chunks of JSON.
Key names with spaces will be changed to have underscores, as BrightScript doesn't allow spaces in associative array key names.
That said, you may find it sufficient for your needs.
-- GandK Labs
Check out Reversi! in the channel store!
Check out Reversi! in the channel store!

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2012
10:29 AM
Re: Can brightscript parse json?
"kbenson" wrote:
as BrightScript doesn't allow spaces in associative array key names.
Actually, I think it does:
BrightScript Debugger> test={}
BrightScript Debugger> test["this is a test"]="hello"
BrightScript Debugger> ?test
this is a test: hello
BrightScript Debugger> ?test["this is a test"]
hello
BrightScript Debugger>
- Joel
renojim
Community Streaming Expert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2012
10:32 AM
Re: Can brightscript parse json?
"kbenson" wrote:
Key names with spaces will be changed to have underscores, as BrightScript doesn't allow spaces in associative array key names.
That's not true. You can have key names with spaces, but you have to use AddReplace and Lookup to access the key. Example:
x = CreateObject("roAssociativeArray")
x.AddReplace("this key has spaces","this is the value")
print x.Lookup("this key has spaces")
-JT
Roku Community Streaming Expert
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.
Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.
I am not a Roku employee.

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2012
11:04 AM
Re: Can brightscript parse json?
"renojim" wrote:"kbenson" wrote:
Key names with spaces will be changed to have underscores, as BrightScript doesn't allow spaces in associative array key names.
That's not true. You can have key names with spaces, but you have to use AddReplace and Lookup to access the key. Example:x = CreateObject("roAssociativeArray")
x.AddReplace("this key has spaces","this is the value")
print x.Lookup("this key has spaces")
-JT
Actually, keys with spaces work just fine with the square bracket notation, too...
Example:
x = {}
x["this key has spaces"] = "this is the value"
print x["this key has spaces"]
For clarification for the OP, the problem kbenson was referring to was that the inline associative array syntax that the SimpleJSON parsers use doesn't allow for quoted key names, so spaces have to be replaced. The original JSON parser for BrightScript used a brute force method that did support spaces, but was extremely slow parsing. The SimpleJSON library uses RegEx to finesse the JSON into a format that is natively parsable by BrightScript, with a few tradeoffs.
If the API your using provides an XML format, the native BrightScript XML parser is infinitely faster than the community provided JSON parsers, so that would likely be a better option.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
lmsilva
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2012
06:10 PM
Re: Can brightscript parse json?
Thank you so much!
I tried the librokudev library, pretty cool stuff!
Thanks,
Luis
I tried the librokudev library, pretty cool stuff!
Thanks,
Luis
kbenson
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2012
10:21 AM
Re: Can brightscript parse json?
"TheEndless" wrote:
kbenson was referring to was that the inline associative array syntax that the SimpleJSON parsers use doesn't allow for quoted key names, so spaces have to be replaced. The original JSON parser for BrightScript used a brute force method that did support spaces, but was extremely slow parsing. The SimpleJSON library uses RegEx to finesse the JSON into a format that is natively parsable by BrightScript, with a few tradeoffs.
Yep, that's it. I was mis-remembering the details of the problem, and thus misspoke. Thanks for the clarification.
-- GandK Labs
Check out Reversi! in the channel store!
Check out Reversi! in the channel store!