[swift-evolution] TreeLiteralConvertible

Brent Royal-Gordon brent at architechies.com
Fri Apr 15 17:12:25 CDT 2016

> Aren’t JSON arrays and objects actually the same thing? They’re both essentially just ordered dictionaries, with objects mapping keys to properties, functions etc., while arrays are just a dictionary where the keys are consecutive integer (or should be, as long as you don’t mess with them)

You're confusing JSON with JavaScript.

JSON is a wire format which includes support for certain, specific types: objects (basically, dictionaries with string keys and heterogenous values), arrays (with heterogenous values), strings, booleans, doubles, and nulls. JSON has nothing to say about how these things are represented in memory once they're parsed out of the wire format.

JavaScript is a language with a prototype-based object system and a literal syntax which happens to be a superset of JSON. The statements you make about how "arrays are just objects with consecutive integer keys" and so on are true of JavaScript arrays, but they have nothing to do with JSON, merely with how JSON is conventionally represented once it's read into JavaScript.

Brent Royal-Gordon

More information about the swift-evolution mailing list