I am encountering difficulties while attempting to access COLUMN_JSON data in JavaScript. I referred to a MariaDB JSON example and inserted it into a table with the following query:
UPDATE myTable
SET myJsonColumn = COLUMN_CREATE('color', 'blue', 'size', 'XL')
WHERE 1
Upon inspecting it through MySQL Workbench, everything seems fine:
Binary view:
0x00000000 7b 22 73 69 7a 65 22 3a 22 58 4c 22 2c 22 63 6f
0x00000010 6c 6f 72 22 3a 22 62 6c 75 65 22 7d
Text view:
{"size":"XL","color":"blue"}
However, when the data is accessed in JavaScript via Sequelize, the output appears like this:
console.log(data):
3sizecolor!XL!blue
console.log(util.inspect(data)):
<Buffer 04 02 00 09 00 00 00 03 00 04 00 33 00 73 69 7a 65 63 6f 6c 6f 72 21 58 4c 21 62 6c 75 65>
JSON.stringify(data):
{"type":"Buffer","data": [4,2,0,9,0,0,0,3,0,4,0,51,0,115,105,122,101,99,111,108,111,114,33,88,76,33,98,108,117,101]}
I am unsure of the most effective way to interpret this data. Both JSON.parse() and JSON.stringify() do not seem to provide the desired results for me.
The myJsonColumn is defined as a BLOB datatype in the Sequelize model:
myJsonColumn: Sequelize.BLOB,
What would be the optimal approach to interpret this data as a JSON structure in JavaScript?