Closed MAGNAT2645 closed 4 years ago
Cool idea - all the object getters actually already return default values when a key is missing, but you can't override them by a param. Array getters have built-in key existence checking in GetIndexAsString
, but ultimately it returns a default value anyway. I think adding a param for this is a good idea, will aim for the next release.
There's also one thing (idk if i should add it as another issue), when you use functions like json_merge would be good to have autoclosing option (like json_merge(JSON_Object to, JSON_Object from, bool replace = true, bool autoclose = false
) so if object to
already has object-typed keys, they'll be closed (via .Cleanup + .Close maybe) before being overwritten (when replace
= true).
My only concern with automatic garbage collection in json_merge
is the fact that we are not tracking instance references. If you happen to have an instance with more than one reference which is replaced during a merge then all other references to that instance will be rendered invalid. This same issue is mentioned in the "Cleaning Up" section of the README, the only difference being that Cleanup()
is called manually and so the issue can be anticipated. I don't like the idea of introducing a "side effect" to merging, but if it is well documented and has a sensible default (probably autocleanup = false) then I suppose it's not a bad thing to have. I will hopefully have a release with these features tagged in the next few hours.
Would be good to implement default values to most getter functions like JSON_Object.GetInt (GetBool and etc.)
Code Snippet №1 (this might be better than 2nd):
Code Snippet №2:
So there won't be need to check for key existence.