Site Moved

This site has been moved to a new location - Bin-Blog. All new post will appear at the new location.


Invalid JSON

I just read a post in Simon Wallace's blog about Invalid JSON. The main point is that valid JSON strings must be enclosed in a double quote(") - not a single quote(').

In JSON (unlike in JavaScript) these MUST be double-quoted strings. In fact, ALL strings in JSON must be enclosed in double quotes (JavaScript also allows single quotes; JSON does not).

Sorry guys, but my JSON generation function created JSON with single quotes. I have already updated and uploaded the modified version - but if you are using the old version, get the modified function from the sql2json() page.

If you have never heard of this function before, sql2json() function will take a SQL query as it argument, execute it, fetch its result, convert it to a JSON string and then return the JSON string. This is extreamly useful if you are creating Ajax applications and decide to use JSON over XML. If you have decided to use XML, take a look at my XML Parser for JavaScript instead.

Guess I should have read JSON's RFC(RFC 4627 - text file) before creating the function. And I have been creating a lot of converters recently - the great '2' functions.

Converts SQL Results to JSON String - the function we were talking about just now.
xml2array() for PHP
Converts a XML string to a PHP array. xml2array() is a easy to use PHP function that will convert the given XML text to an array in the XML structure. Kind of like my Javascript xml2array() function.
xml2array() for JavaScript
Converts a XML document to a JavaScript array.