> On 15 Apr 2016, at 16:48, John McCall via swift-evolution > <[email protected]> wrote: > The JSONValue type needs to be able to embed both JSON arrays and JSON > objects,
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), compilers will optimise them behind the scenes if they can, but there’s essentially no specific array type in Javascript, the array functions are just manipulating a dictionary in an array-like fashion. Anyway, this is probably a reason why Swift dictionaries shouldn’t be used to implement a tree in this way, as they have no strict ordering, but the order of values in JSON is important, particularly when it comes to duplicate keys (the last always one takes precedence), and it’s technically okay to parse multiple duplicates values and combine them together if you want. While the original post is an interesting way to define this structure, I think a specialised type is required to really capture this usefully. _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
