Roku Developer Program

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

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. Smiley Happy 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
0 Kudos
17 Replies
Highlighted
RokuMarkn
Level 7

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
0 Kudos
Highlighted
TheEndless
Level 7

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.. Smiley Tongue

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)
0 Kudos
Highlighted
Rek
Level 7

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.. Smiley Tongue

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.
0 Kudos
Highlighted
malloys
Level 7

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.. Smiley Tongue

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.
0 Kudos
Highlighted
EnTerr
Level 9

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.
0 Kudos
Highlighted
malloys
Level 7

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
0 Kudos
Highlighted
RokuMarkn
Level 7

Re: Built-in ToJSON function

It's not currently in the 3.1 firmware.

--Mark
0 Kudos
Highlighted
Roku Employee
Roku Employee

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
0 Kudos
Highlighted
gonzotek
Level 8

Re: Built-in ToJSON function

"RokuJoel" wrote:
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
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.
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
0 Kudos