I exported my database with JSON columns in it. After I migrated to a new server, my import crashed every time with an error like:
cannot create a JSO
I had this problem dealing with exports made by Sequel Pro. I unchecked the Output BLOB fields as hex
option and the problem went away. Visually inspecting the export showed legible JSON instead of binary.
This odd issue was occurring when running a simple UPDATE query:
update some_table set json_attr = '{"test":168}' where id = 123456;
Restarting MySQL fixed it. Was not able to pinpoint the cause.
Edit: We are using Aurora. It looks like it was related to us having a weird configuration where the same instance handled both master & slave/reader connections.
change collation to utf8_general_ci. worked for me.
All MySQL JSON data type information must be UTF8MB4 character set not BINARY.
Lorcan's answer did help me well as a start, but converting all binary values created a bunch of other error messages like Duplicate entry [...] for key 'PRIMARY'
. Finally I figured out that JSON entries all started with 5B or 7B, and closed with 5D or 7D, which of course means they start with [
or {
and end with ]
or }
. So what worked for me was to regex-replace only those entries:
Find: (X'5B[^,\)]*5D')
Replace: CONVERT($1 using utf8mb4)
then
Find: (X'7B[^,\)]*7D')
Replace: CONVERT($1 using utf8mb4)
Et voilá, all import errors gone! (At least for my case)
For those using Sequel Pro around June 2019, in addition to unchecking the "Output BLOB fields as hex option" (as mentioned above) - you also need to use the nightly build, which added support for JSON types 2 years ago. This support has not yet made it to the official release.