Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cdkelly
Visitor

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?

EX:
obj = CreateObject("roAssociativeArray")
obj.SetModeCaseSensitive()
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
2 REPLIES 2
RokuMarkn
Visitor

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


--Mark
0 Kudos
cdkelly
Visitor

Re: Associative Array to JSON

That worked. Thank you!
0 Kudos