Lost in translation
Recommended by 0 users
The JSON round trip
It is a clustered pub-sub system, with zero points of failure.
$itemGuitar = array( 'id' => 'itemGuitar',
'description' => 'Pete Townshend once played this guitar while his own axe ' . was in the shop having bits of drumkit removed from it.',
'price' => 5695.99,
'urls' => array('http://www.thewho.com', 'http://en.wikipedia.com/wiki/Pete_Townshend') );
$output = json_encode($itemGuitar); print($output);
"description": "Pete Townshend once played this guitar...",
"urls": ["http://www.thewho.com", "http://en.wikipedia.com/wiki/Pete_Townshend"]
var itemDetails = eval('(' + jsonDataString + ')');
var itemDetails = eval('(' + request.responseText + ')');
This is the typical JSON round trip. But there are problems here … big, big problems.
Subtlety and nuance destroy solid code
First, there’s a major problem in that, this sort of code relies heavily on a translator. In this case, the translator is the JSON interpreter and related code, and there are in fact two dependencies: a JSON interpreter for Java in the form of what eval() does with the response text, and the JSON interpreter for PHP. As of PHP 5.2.0, that interpreter is included with PHP, but it’s still essentially an external dependency, separate from the core of PHP.
Now, this isn’t a rant about translation itself. There’s nothing to suggest that there are problems in taking, say, an “I” and turning it into an “i”, or something that’s item 1 in an array and reporting it as being item 2 in an array. There’s a lot of testing that occurs before JSON tools are ever released to ensure that what gets reported is correct, and accurate round tripping from a client to a server and back again are possible. Lots and lots and lots of testing is involved …And that is in fact a problem.
A selection of JSON toolkits.
That’s not in itself bad. In fact, it argues for the popularity of JSON that it’s constantly put to new use. But with the “new” comes the “does it support the new?” So JSON has to evolve from time to time, and that means testing, and retesting, and release on tons of platforms. You, the programmer, may have to rearrange your data; or wait on a release to support your needs; or hack at JSON yourself. Again, many of these are just the so-called costs of programming.