47

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?

1
  • 13
    Use JSON_UNQUOTE or column->>path (MySQL 5.7.13 and later): The ->> operator can be used wherever JSON_UNQUOTE(JSON_EXTRACT()) would be allowed.. Commented May 24, 2016 at 8:34

2 Answers 2

96

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

Sign up to request clarification or add additional context in comments.

Comments

-7

you can use replace() with it to remove quotation marks

SELECT replace(JSON_EXTRACT('{"username":"Alexander"}', '$.username'), '\"', '');

1 Comment

This is working only if there is no " in the value. This shouldn't be used. In json, " are encoded with \". JSON_EXTRACT returns directly the value without converting it to plain text. Not only you remove all " but you'll end up with extra \. Correct me if I am wrong!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.