Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upWhen converting the JS objects to JSON get associative arrays for ObjectIds #64
Comments
|
what js data type are they? |
|
Sync docs say Array of Objects ( |
|
object IDs in brave/sync are Uint8Arrays. to avoid the weird conversion and preserve order, you can serialize them with we have the same issue in browser-laptop, so i think it is a general issue with JSON.stringify. |
|
Yeah, the main issue is that the ids are just child properties in the data structure, and it is by far better to just Also, it is JS's stringify that is leading to the dictionary JSON, so this isn't an iOS thing, this is all native javascript. I use JS to first convert the returned result to JSON (which is where this is happening), and then later convert it to the native language. The current solution is workable, just a bit hacky as I need to stitch the ID together from the JSON associative array. I am not expecting or recommending any changes at this point, but wanted to get a discussion / bring awareness to this. |
I just remembered that JSON.stringify takes a replacer function as the second argument: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters. So you could use this to convert any Uint8Arrays to Arrays. |
|
Oh, beautiful. This could help bunches. Appreciate it! This is what I quickly came up with. Any thoughts / recommendations are welcome
|
|
i would probably do
|
|
Yeah, me too. Haha. Thanks, much nicer. |
Since mobile clients don't natively support JS I am converting the JS objects returned, to JSON (via
JSON.stringify()), and then converting them to native objects. But the object IDs get encoded as associative arrays like:This leads to some odd behavior, as native conversion does not guarantee retained order. Also, makes passing
objectIdsinto the library more difficult.