need to store in json different keys with same value, like this:
{
"key1" : "valueA",
"key2" : "valueA",
"key3" : "valueA",
"key4" : "valueB",
"key5" : "valueB",
"key6" : "valueB",
}
But because there will be many keys associated with the same value, is there an option to optimize the code, e.g. using an array for the keys? This was throwing me errors...
{
["key1","key2","key3"] : "valueA",
["key4","key5","key6"] : "valueB
}
Nope. In JSON all keys must be strings. The best you could do is:
{
"key1,key2,key3": "valueA",
"key4,key5,key6": "valueB"
}
(Or some other delimiter in place of ,
.)
But then, of course, you'll need to do some processing after decoding the JSON to split them back up into multiple keys.
However, if your concern is with the cost of sending the data over HTTP, then just make sure your server has gzip compression enabled. It will do a great job of compressing those repeated values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With