Before inserting JSON-encoded data in MySQL, do you first JSON encode the data and then escape it prior to inserting, or do you first escape the data before JSON encoding it and then insert it?
First JSON encode it then escape it prior to inserting in the database.
The very statement of question is wrong.
Don't use mysql_real_escape_string - it's deprecated. http://php.net/manual/en/function.mysql-real-escape-string.php If you use one of the DB libraries such as PDO, then that will do the work for you. See real escape string and PDO