Forum Discussion

cdkelly's avatar
cdkelly
Visitor
12 years ago

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.

2 Replies

  • 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