I just discovered Scriptable and I’m loving it, thank you!
I made a scripted based on the macstories example. When I select a dictionary inside an array it changes the order of the entries.
The following code should recreate my issue:
let url = "https://macstories.net/feed/json"
let req = new Request(url)
let json = await req.loadJSON()
console.log(json["items"][0])
In the original JSON the order is: “id”, “url”, “title”, “content_html” …
but using loadJSON() the order is: “author”, “id”, “content_html”, “title”…
For my use the order is important because I have one event per entry in chronological order.
Technically the object order is not necessarily maintained, but where a parser can maintain it, it can be useful. But for transportability, you would ideally design in any sorting you require.
As an aside, here’s a good article that talks about the topic and provides good supporting arguments for the retention of ordering.
Whilst I’m all for defensive and transportable coding, it is of course a very useful feature to have if the code is only ever being run in the one place. Simplicity is always a winner.
as long as the “items” order is not being changed, how does that matter? When you are looping the items. items[0].id is always going to be items[0].id no?
It comes down to JSON Objects in Javascript are not ordered lists like Array are. The way you get data out of a JSON object is based on a key name, not a position index like Arrays.