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
<https://fiddle.basex.org/?share=%28%27query%21%27%2803.*2%2C%5Cn%28.30*24%21%27%27%7Emode%21%27XQuer7%7BBaseX%7D4Type%21%27xml%27%29*%29+%3D%3E+serializ9%28%22method6json%223%22indent-tru6+%3A+.%22data-arra7%28+1+to+580%22foo6bar%2229%7D8%7D3%2C+4%27%7Econtext6-%227y+8+%299e%7B%0198764320.-*_>:

{'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
<https://fiddle.basex.org/?share=%28%27query%21%27for+%24map+in+%7B%280.-%29.%28-.0%29%7D+return+serialize%7B%24map.%28%22method3json%22.%22indent*true%7B%7D62%21%27%27%7Emode%21%27XQuer4%7BBaseX2Type%21%27xml%27%293+%3A+-%22data*arra4%28+1+to+56.%2C+0%22foo3bar%222%7D%27%7Econtext3*%224y+6+%29%0164320.-*_>:

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?



Reply via email to