Bug #79050 | JSON Path does not support literal escape of double quote character | ||
---|---|---|---|
Submitted: | 1 Nov 2015 0:37 | Modified: | 10 Nov 2015 8:50 |
Reporter: | Roland Bouman | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: JSON | Severity: | S3 (Non-critical) |
Version: | 5.7.9 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[1 Nov 2015 0:37]
Roland Bouman
[1 Nov 2015 0:51]
Roland Bouman
Creating the path with JSON search also works: mysql> SELECT JSON_EXTRACT(JSON_OBJECT('"', '1'), JSON_UNQUOTE(JSON_SEARCH(JSON_OBJECT('"', '1'), 'one', '1'))); +---------------------------------------------------------------------------------------------------+ | JSON_EXTRACT(JSON_OBJECT('"', '1'), JSON_UNQUOTE(JSON_SEARCH(JSON_OBJECT('"', '1'), 'one', '1'))) | +---------------------------------------------------------------------------------------------------+ | "1" | +---------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) Indicating that the path itself is fine. It's just that for some reason the equivalent string literal is not parsed or accepted - it should.
[1 Nov 2015 11:38]
MySQL Verification Team
Hello Roland, Thank you for the report. Thanks, Umesh
[2 Nov 2015 10:17]
Knut Anders Hatlen
Hi Roland, I don't think this is a bug. It is caused by the parser's default (non-standard, I think) handling of backslash in string literals. After the string literal '$."\""' has gone through the parser, the backslash is gone: mysql> SELECT '$."\""'; +-------+ | $.""" | +-------+ | $.""" | +-------+ 1 row in set (0,00 sec) The two string literals '$."\""' and '$."""' represent the same string value, and the path $.""" is invalid. So in order to create a string literal for the path $."\"", one has to write '$."\\""', like this: mysql> SELECT JSON_EXTRACT(JSON_OBJECT('"', 1), '$."\\""') AS JE; +------+ | JE | +------+ | 1 | +------+ 1 row in set (0,00 sec) Alternatively, one can disable the special meaning of backslashes within string literals by enabling the NO_BACKSLASH_ESCAPES SQL mode. See: https://dev.mysql.com/doc/refman/5.7/en/string-literals.html https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_backslash_escapes mysql> SET sql_mode='NO_BACKSLASH_ESCAPES'; Query OK, 0 rows affected, 1 warning (0,00 sec) mysql> SELECT JSON_EXTRACT(JSON_OBJECT('"', 1), '$."\""') AS JE; +------+ | JE | +------+ | 1 | +------+ 1 row in set (0,00 sec)
[10 Nov 2015 8:50]
Roland Bouman
Knut, I think I understand. Thanks for the clarification! Perhaps this should be clarified in the docs (JSON path syntax section)?
[17 Nov 2015 9:32]
Knut Anders Hatlen
I've filed bug#79306 for clarifying the documentation. Thanks.