ParseJSON order of information not guaranteed

From the Language reference for Xojo.Data.ParseJSON:

I am unsure of what this means in practical terms when the JSON text I am working contains arrays of dictionary-like items. From my tests the Xojo.Data.ParseJSON command seems to work just I hope it would, retaining order of the items. Does anyone know under what circumstances might it throw off the order in which the JSON stores it?

Here’s a shortened example of the JSON (in real life this often will have hundreds of items in each array, but it will give you an idea):

{"libraries":[ {"libraryName":"My Categories","libraryID":0,"categories": [{"categoryName":"Stuff I've learned","categoryID":1,"items":"222,235,336"},{"categoryName":"July 15","categoryID":2,"items":"1000,1001,1222"},{"categoryName":"Learn later","categoryID":3,"items":"1,2,3,4,5,6"}]}, {"libraryName":"Egyptian Arabic","libraryID":1,"categories": [{"categoryName":"Animals","categoryID":1,"items":"322,335,336"},{"categoryName":"Art and Literature","categoryID":2,"items":"422,435,436"},{"categoryName":"Clothing and Accessories","categoryID":3,"items":"522,535,536"}]}, {"libraryName":"Modern Standard Arabic","libraryID":2,"categories": [{"categoryName":"Animals","categoryID":1,"items":"322,335,336"},{"categoryName":"Art and Literature","categoryID":2,"items":"322,335,336"},{"categoryName":"Clothing and Accessories","categoryID":3,"items":"322,335,336"}]} ]}

When I parse this, Xojo gives me just what I would hope for, in terms of the order of the items:


  • My Categories
    - Stuff I’ve learned
    - July 15
    - Learn later
  • Egyptian Arabic
    - Animals
    - Art and literature
    - Clothing and accessories
  • Modern Standard Arabic
    - Animals
    - Art and literature
    - Clothing and accessories[/code]

Thanks for any insights you can give into this.

Arrays are kept in order, it’s just that the other stuff is not guaranteed to stay in the same order.

If you look at each of the objects inside the libraries array, LibraryName may not always be the first property and LibraryId may not always be second.

The reason this is important is that there are some json implementations out there that rely on this order because they allow you to have two identical keys within the same object. Now based on the docs for json, you’re supposed to use an array, but I’ve seen it done. Of course there would be no way to access the second one without some special method…

Ok, that explains it clearly - thanks for letting me know.

And it’s nice that I can use it as is in my project.