Does json_object_get_members() returns names in same order in which the members were added?

The documentation doesn’t specify if json_object_get_members() returns names in the same order in which the members were added. I’m on Ubuntu 20.04 so the latest json-glib for my OS doesn’t support json_object_iter_next_ordered so I wonder if I can use json_object_get_members() as a way to iterate the object in the same order in which the members were added?

It appears that this method will return the same order every time (since 6+ years ago), and that added members are ordered in the same way. I would assume this only applies to members that are added by the programmer to that JsonObject instance though.

In other words, yes it appears so, but don’t count on that being the case for parsed JSON.

2 Likes

No, it’s also somewhat guaranteed: the parsing code goes through the same paths as the public API.

The order is maintained because any change to a parsed JSON stream will minimise differences when serialising the same data.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.