If I have a simple SELECT statement like this:
SELECT JSON_EXTRACT('{"username":"Alexander"}', '$.username');
I would expect it to return Alexander
, but instead it returns "Alexander"
. How can I get rid of the quotes? Why does this function even return the quotes too?
Try this: str_replace('"', "", $string); str_replace("'", "", $string); Otherwise, go for some regex, this will work for html quotes for example: preg_replace("/<!
In MySQL, the JSON_EXTRACT() function returns data from a JSON document. The actual data returned is determined by the path you provide as an argument. You provide the JSON document as the first argument, followed by the path of the data to return.
- Supports all the JSON types – Numbers , string, Bool , objects & arrays.
Two aggregate functions generating JSON values are available. JSON_ARRAYAGG() returns a result set as a single JSON array, and JSON_OBJECTAGG() returns a result set as a single JSON object.
You can use JSON_UNQUOTE
to achieve this.
select JSON_UNQUOTE(JSON_EXTRACT(base, '$.scope')) as scope from t_name
ref: Functions That Modify JSON Values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With