kurtn718
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2014
09:24 PM
Built-in ToJSON function
Hi. Is there a built-in ToJSON function, similar to ParseJSON?
I couldn't find one in the docs, but I was able to write the following function taking an roAssociativeArray as the input - which works for what I need.
If there is a built-in function, I'll probably replace the code below with that function. If one doesn't exist, then this is my first contribution to the forum. 🙂 If there is a way to write the code better, please offer suggestions.
Thanks,
Kurt
-------
Function ToJSON(jsonData as Object) as String
jsonRequest = "{"
for each key in jsonData
if jsonRequest <> "{" then
jsonRequest = jsonRequest + ","
endif
jsonRequest = jsonRequest + chr(34) + key + chr(34) + " : " + chr(34) + jsonData[key] + chr(34)
end for
jsonRequest = jsonRequest + "}"
return jsonRequest
End Function
I couldn't find one in the docs, but I was able to write the following function taking an roAssociativeArray as the input - which works for what I need.
If there is a built-in function, I'll probably replace the code below with that function. If one doesn't exist, then this is my first contribution to the forum. 🙂 If there is a way to write the code better, please offer suggestions.
Thanks,
Kurt
-------
Function ToJSON(jsonData as Object) as String
jsonRequest = "{"
for each key in jsonData
if jsonRequest <> "{" then
jsonRequest = jsonRequest + ","
endif
jsonRequest = jsonRequest + chr(34) + key + chr(34) + " : " + chr(34) + jsonData[key] + chr(34)
end for
jsonRequest = jsonRequest + "}"
return jsonRequest
End Function
17 REPLIES 17

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2014
09:42 AM
Re: Built-in ToJSON function
There is an undocumented global function which does what you want:
FormatJSON(aa as Object) as String
I'm not sure why this isn't documented, probably an oversight.
--Mark
FormatJSON(aa as Object) as String
I'm not sure why this isn't documented, probably an oversight.
--Mark

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2014
10:14 AM
Re: Built-in ToJSON function
"RokuMarkn" wrote:
There is an undocumented global function which does what you want:
FormatJSON(aa as Object) as String
I'm not sure why this isn't documented, probably an oversight.
--Mark
Wow.. that should definitely be documented! I've written and refined three different versions of the same functionality so far in BS.. 😛
Any chance it's also available in the 3.1 firmware?
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)
Rek
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2014
12:45 PM
Re: Built-in ToJSON function
"TheEndless" wrote:"RokuMarkn" wrote:
There is an undocumented global function which does what you want:
FormatJSON(aa as Object) as String
I'm not sure why this isn't documented, probably an oversight.
--Mark
Wow.. that should definitely be documented! I've written and refined three different versions of the same functionality so far in BS.. 😛
Any chance it's also available in the 3.1 firmware?
Agreed, I hit the same problem and ended up relying on librokudev's rdJSONBuilder function.
malloys
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2014
11:16 AM
Re: Built-in ToJSON function
"TheEndless" wrote:"RokuMarkn" wrote:
There is an undocumented global function which does what you want:
FormatJSON(aa as Object) as String
I'm not sure why this isn't documented, probably an oversight.
--Mark
Wow.. that should definitely be documented! I've written and refined three different versions of the same functionality so far in BS.. 😛
Any chance it's also available in the 3.1 firmware?
Bump.
Roku support...
Any answer on the 3.1 question?
Also, it appears the FormatJSON global function is still not in the online docs. - Can we get the docs updated?
BTW... it's hard to be 100% sure the docs haven't been updated, since the developer wiki's dashboard functionality that listed recent changes went missing sometime in the last month or two - any chance we can get that reinstated? That was a very useful feature.
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2014
01:01 PM
Re: Built-in ToJSON function
"malloys" wrote:
Bump.
Roku support...
Any answer on the 3.1 question?
Also, it appears the FormatJSON global function is still not in the online docs. - Can we get the docs updated?
BTW... it's hard to be 100% sure the docs haven't been updated, since the developer wiki's dashboard functionality that listed recent changes went missing sometime in the last month or two - any chance we can get that reinstated? That was a very useful feature.
Useful it is indeed, though in a corner hard to find: http://sdkdocs.roku.com/pages/recentlyu ... key=sdkdoc
Good luck (you will need it) with the first two items.
malloys
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2014
01:53 PM
Re: Built-in ToJSON function
"EnTerr" wrote:"malloys" wrote:
Bump.
Roku support...
Any answer on the 3.1 question?
Also, it appears the FormatJSON global function is still not in the online docs. - Can we get the docs updated?
BTW... it's hard to be 100% sure the docs haven't been updated, since the developer wiki's dashboard functionality that listed recent changes went missing sometime in the last month or two - any chance we can get that reinstated? That was a very useful feature.
Useful it is indeed, though in a corner hard to find: http://sdkdocs.roku.com/pages/recentlyu ... key=sdkdoc
Thanks - discovered that myself a few minutes after posting.
FYI, the view I was referring to was the Dashboard URL/level itself ( http://sdkdocs.roku.com/dashboard.action ), but this looks similar enough.
In any case, I think we all agree that FormatJSON() still needs to be documented in the BrightScript Language Guide.
Cheers

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2014
03:44 PM
Re: Built-in ToJSON function
It's not currently in the 3.1 firmware.
--Mark
--Mark

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2014
10:52 AM
Re: Built-in ToJSON function
Before functions like FormatJSON are published in the documentation, they need to go through an API review process. Anything that hasn't, is potentially subject to change, so basing a public channel on an upublished function is somewhat risky.
- Joel
- Joel

gonzotek
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2014
01:25 PM
Re: Built-in ToJSON function
"RokuJoel" wrote:You could tag such features as *experimental* or similar in the documentation(with a formal statement that they're subject to change/removal) and then receive potentially useful feedback on them like bugs, enhancement requests, and discussion of the feature documentation, all prior to having to officially support it. The way I see it, if it's going to be discussed in the forum anyway, it might as well be properly organized. There's a lot of precedent for documenting not-yet-released features in, just for instance, web browsers and web technologies.
Before functions like FormatJSON are published in the documentation, they need to go through an API review process. Anything that hasn't, is potentially subject to change, so basing a public channel on an upublished function is somewhat risky.
- Joel
Remoku.tv - A free web app for Roku Remote Control!
Want to control your Roku from nearly any phone, computer or tablet? Get started at http://help.remoku.tv
by Apps4TV - Applications for television and beyond: http://www.apps4tv.com
Want to control your Roku from nearly any phone, computer or tablet? Get started at http://help.remoku.tv
by Apps4TV - Applications for television and beyond: http://www.apps4tv.com