2012
01.10

Today I realized theres a pretty simple way, to generate JSON straight from MySQL.

I use it this way:

1
SELECT CONCAT('[',GROUP_CONCAT(CONCAT('{name:',USER.name,''),CONCAT(',email:',USER.email,'}')),']') FROM USER WHERE STATUS = 'active' ORDER BY created ASC

4 comments so far

Add Your Comment
  1. And if the user name contains JSON char : {, }, [, ] ?? Bogue !

  2. Do you really think it’s normal to have [] and {} in a username? I don’t think yo. If you allow characters like this, why don’t you open up your database for some nice sql injection. I would like to have a username like this: “djzone'; drop database;”

  3. What I mean is that I’m not sure that no data in the database does not contain “{“, “}”, “[" or "]” (comments data for example…)

    Also the characters “{“, “}”, “[" or "]” are not used for SQL injection.
    You’re example “djzone’; drop database;” does not contain this character…

  4. What I mean is, it’s NOT acceptable to have ANY username with special characters in, any other that “.”, “-“, “_” and @ if you use e-mail as username.