https://bugzilla.wikimedia.org/show_bug.cgi?id=10887
--- Comment #9 from Brion Vibber <[email protected]> --- (In reply to comment #6) > Resolving as LATER. [] is legal syntax, but inconsistent. If Python can't > handle [], that's a problem in their JSON interpreter. We could fix this in > theory, but it's so much hassle that it's only practical to do if the > formatting code as a whole is revised. Just to clarify on this old bug -- the Python JSON interpreter can handle [] just fine, but it creates a *list* (equivalent to JS *array*) instead of a *dict* (equivalent to JS *object*). This can cause problems if you do some kind of operation on what you expected would be a dict/object/map/hash/associative array. This is not Python-specific, but could also cause problems in Java, Objective-C, C++, and ... basically anything but PHP .... especially for those with strong typing, you might even throw an error when simply assigning an extracted object to a variable of what turns out to be the wrong type. A few possible ways to resolve this, should we care to: a) use objects instead of associative arrays in the PHP code in the first place b) use a special array key value that the JSON formatter knows to drop from the output, that forces an otherwise empty array to be treated as an associative array c) create a special object type that wraps associative arrays in the API output, that the JSON formatter knows how to deal with Under PHP 5.4, option c) can be combined with the JsonSerializable interface to ensure that a wrapped associative array outputs the way we want it even if people use json_encode() directly, so this could be used outside the API as well. Combine that with the array-like object interface, and the array wrapper also becomes transparent to array-like uses in PHP. I think this is my favorite method... $data['pages'] = $someArray; // ... echo json_encode( $data ); // {"pages":[]} OOPS! fix to: // wrap an array that might be empty $data['pages'] = new JsonAssociativeArray( $someArray ); // ... echo json_encode( $data ); // {"pages":{}} or // start with an empty array $foo = new JsonAssociativeArray(); if ( $condition ) { $foo["bar"] = "baz"; } $data['pages'] = $foo; // ... echo json_encode( $data ); // {"pages":{}} -- You are receiving this mail because: You are the assignee for the bug. You are on the CC list for the bug. _______________________________________________ Wikibugs-l mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/wikibugs-l
