First week having to deal with a MYSQL database and JSON field types and I cannot seem to figure out why values are encoded automatically and then returned in encoded format.
Given the following SQL
-- create a multiline string with a tab example
SET @str ="Line One
Line 2 Tabbed out
Line 3";
-- encode it
SET @j = JSON_OBJECT("str", @str);
-- extract the value by name
SET @strOut = JSON_EXTRACT(@J, "$.str");
-- show the object and attribute value.
SELECT @j, @strOut;
You end up with what appears to be a full formed JSON object with a single attribute encoded.
@j = {"str": "Line One\n\tLine 2\tTabbed out\n\tLine 3"}
but using JSON_EXTRACT to get the attribute value I get the encoded version including outer quotes.
@strOut = "Line One\n\tLine 2\tTabbed out\n\tLine 3"
I would expect to get my original string with the \n \t all unescaped to the original values and no outer quotes. as such
Line One
Line 2 Tabbed out
Line 3
I can't seem to find any JSON_DECODE or JSON_UNESCAPE or similar functions.
I did find a JSON_ESCAPE() function but that appears to be used to manually build a JSON object structure in a string.
What am I missing to extract the values to the original format?