After some recent announcement of ordered maps in the BaseX
fiddle I played around with some JSON serialization, to my
surprise the result is different whether I use
the serialize function directly on a single map:
{'foo' : 'bar', 'data' : array { 1 to 5 }} =>
serialize({'method' : 'json', 'indent' : true() }),
{'data' : array { 1 to 5 }, 'foo' : 'bar'} =>
serialize({'method' : 'json', 'indent' : true() })
gives
{
"foo": "bar",
"data": [
1,
2,
3,
4,
5
]
}
{
"data": [
1,
2,
3,
4,
5
],
"foo": "bar"
}
or in a for
.. return:
for $map in ({'foo' : 'bar', 'data' : array { 1 to 5 }}, {'data' : array { 1 to 5 }, 'foo' : 'bar'}) return serialize($map, {'method' : 'json', 'indent' : true() })
gives
{
"foo": "bar",
"data": [
1,
2,
3,
4,
5
]
}
{
"foo": "bar",
"data": [
1,
2,
3,
4,
5
]
}
Should the JSON serialization reflect the map as created or is
that still random/arbitrary order for the properties?