Last modified: 2012-07-05 19:51:03 UTC
Here's an example: { "label": "Follow", "shortdesc": "Implements "tail -f" functionality", "uri" : "http://localhost/wiki/index.php?title=Follow", } This is output from {{#ask[[someprop::someval]] | ?shortdesc=}}. "Shortdesc" is of type String, so it should be expected to possibly contain quotes, as above. However, this short circuits the decoding of the JSON -- eg, php's own decode_json will fail here and return NULL. Parsing the reply to escape the quotes -- so: "Implements \"tail -f\" functionality" corrects the issue and decode_json works properly. Obviously, SMW should not be providing bad JSON data!
The problem is not limited to property values. Valid MediaWiki article names containing quotes (such as "Weird Al" Yankovic) also create invalid JSON output: { "label" : ""Weird Al" Yankovic", "uri" : "http://localhost/mediawiki/index.php?title=""Weird Al" Yankovic", ... } I fixed this particular case by hacking SMW_QP_JSONlink.php to do a str_replace: valuestack[] = '"uri" : "' . $wgServer . $wgScriptPath . '/index.php?title=' . str_replace("\"", "\\\"", $prefixedtext) . '"'; As a secondary issue: Notice also that the "label" is getting htmlescaped, which is probably not what is actually wanted in JSON output? Changing this now though would break existing users, so I guess we're stuck with that one?
Fix by Matt Voysey appears to work, see http://code.creativecommons.org/issues/issue847 for more.
The string escape problem is solved with the new JSON export but please be aware that the JSON structure has changed beginning with (bug 37418). [1] http://www.semantic-mediawiki.org/wiki/Help:JSON_format#Structure