symisc / unqlite

An Embedded NoSQL, Transactional Database Engine
https://unqlite.symisc.net
Other
2.11k stars 164 forks source link

Making an empty object in C (unqlite_new_array and jx9_new_array) #125

Closed mdorier closed 3 years ago

mdorier commented 3 years ago

I noticed that unqlite_new_array and jx9_new_array create both objects and arrays. However arrays turn into objects only if I add key/value pairs to them. How can I create an empty object (i.e. {}) in C with unqlite/jx9?

symisc commented 3 years ago

You can't create an empty object from your C code unless you insert some key. The reason is that Object and Arrays share the same implementation under the hood (Hashmap) and arrays take precedence over objects when the instance is empty (Assumed to be an indexed array).