Skip to content

MySQL JSON Query sends random numbers

I’m writing a MySQL Query in Python using pymysql to send JSON data to a MySQL table. When it sends the data, the following results are produced.

The code I used to send the data is the following:

The exec_sql function is:

An example line of JSON data is

My SQL table was setup as follows:

Advertisement

Answer

The bytes are not random. They are the hex representation of ASCII bytes in your JSON string. Observe:

What you’re seeing is that when you store a JSON string in a binary column (BLOB), MySQL “forgets” that it is supposed to be text, and dumps only the hex encoding of the bytes when you query it.

If you want to store JSON, then use the JSON data type, not BLOB.

User contributions licensed under: CC BY-SA
4 People found this is helpful