Since ECMAScript v5 if I remember correctly object keys are ordered,
because under the hood List object should be used to store keys.


On Mon, Dec 16, 2024 at 4:37 PM Martin Honnen <[email protected]> wrote:

>
> Am 16.12.2024 um 15:19 schrieb Oleksandr Shpak:
>
> Hi Martin,
>
> I found even more weird situation
> parse-json('{"1:aa": 1, "2:bb": 2}')
> returns
> {"2:bb":2.0e0,"1:aa":1.0e0}
>
> Seems like order is inversed
> But,
> parse-json('{"aa": 1, "b": 2, "ab": 3}')
> returns
> {"aa":1.0e0,"ab":3.0e0,"b":2.0e0}
>
> and, finally
> parse-json('{"aa": 1, "b": 2, "ab": 3, "1:aa": 1, "2:bb": 2}')
> returns
> {"aa":1.0e0,"ab":3.0e0,"b":2.0e0,"2:bb":2.0e0,"1:aa":1.0e0}
>
> 🤯
>
> It seems like a bug to me ;)
>
>
> As I said, in XPath 3.1 and XQuery 3.1 maps are unordered collections, you
> might get any order when parsing a particular JSON into an XDM 3.1 map.
>
> If it is any help, in the BaseX fiddle you probably get/see the order
> preservation you want/expect
> <https://fiddle.basex.org/?share=%28%27query%21%275.**8.A6%21%27%27%7Emode%21%27XQuery+%7BBaseX6Type%21%27xml%27%29*A%7D%2C%5Cn579b024ab03.71%3A92%3Abb020%5C%21+4875parse-json%7B%22%286%7D%27%7Econtext7%5C%278%2C+9aa014A%29%22%01A9876540.*_>
> .
>
>
>
>
> If we are talking about the JSON standard, not xQuery, devs will expect
> the function which behaves in the same way as it does in many other
> languages.
>
> Well, I have been around long enough to remember JavaScript/ECMAScript
> objects as unordered so some features change in the course of time, I also
> think, Python, for instance only recently switched to some order
> preservation in its dictionary type.
>
> I don't know what to suggest for the current BaseX release, unfortunately
> http://www.woerteler.de/xquery/modules/ordered-map.html is not accessible.
>


-- 
s0rr0w

Reply via email to