SQL JSON_UNQUOTE function
JSON_UNQUOTE(JSON_EXTRACT(doc, '$.region')) turns '"eu"' into eu. What ->> does in one character, spelled out as a function.
- 類別
- Strings
- Returns
text- In this category
- 141 of 172
語法
JSON_UNQUOTE(json_value)
引擎支援
| 引擎 | Support | 備註 |
|---|---|---|
| SQL Server | Not built in | JSON_VALUE already returns unquoted text |
| PostgreSQL | Not built in | ->> unwraps; no function needed |
| MySQL | 是 | Supported under this name. |
| SQLite | Not built in | json_extract already unwraps |
| Oracle | Not built in | JSON_VALUE already returns unquoted text |
範例
MySQL
SELECT JSON_UNQUOTE(JSON_EXTRACT(config, '$.region')) AS region FROM settings;
MySQL
SELECT config->>'$.region' AS region FROM settings;
小知識
- Prefer ->>: it is exactly JSON_UNQUOTE(JSON_EXTRACT(...)) in one token and reads better in WHERE clauses.
- Only a complete JSON string gets unquoted. JSON_UNQUOTE('eu') and JSON_UNQUOTE('"eu') both come back unchanged, so a malformed value slips through looking like data.
- The other engines unquote by construction (->> on PostgreSQL, JSON_VALUE on SQL Server and Oracle, unwrapping json_extract on SQLite), so this function rarely survives a port.
Questions about JSON_UNQUOTE
Why is my JSON value double-quoted?
JSON_EXTRACT returns JSON, and JSON strings are quoted. Unwrap with JSON_UNQUOTE or the ->> operator when the SQL side wants plain text.
Does JSON_UNQUOTE also unescape?
Yes, it strips quoting and the JSON escapes inside the string, yielding the original text value, not just the outer quotes.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: MySQL.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.