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 8

Associative Array to JSON

Please pardon me if this is a simple solution but I am new to BrightScript.
I need to convert an roAssociativeArray to a JSON object while preserving the case sensitivity of the original keys. Even when setting SetModeCaseSensitive(), the keys will print out in all lowercase. Is there a trick to getting the keys to preserve their case, or a better way to convert an object to JSON keeping the key case?

obj = CreateObject("roAssociativeArray")
obj.PropertyWithCamelCase1 = "String Value"
obj.PropertyWithCamelCase2 = "something else"
obj.PropertyWithCamelCase3 = "another thing"

When I run it through a JSON builder method such as the one found here: viewtopic.php?p=200771
It will be converted to the following string:
"{"propertywithcamelcase1":"String Value","propertywithcamelcase2":"something else","propertywithcamelcase3":"another thing"}"

I need it to look like:
"{"PropertyWithCamelCase1":"String Value","PropertyWithCamelCase2":"something else","PropertyWithCamelCase3":"another thing"}"

Any help is appreciated.
0 Kudos
Level 8

Re: Associative Array to JSON

Using the dot syntax will convert the key to lower-case. The array operator or the AddReplace method will preserve case. SetModeCaseSensitive only affects lookups.

a.One = 1 ' wont preserve case
a["Two"] = 2 ' ok
a.AddReplace("Three", 3) ' also ok

0 Kudos
Level 8

Re: Associative Array to JSON

That worked. Thank you!
0 Kudos