JSON_OBJECT will automatically remove escape characters

This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: JSON_OBJECT会自动去除转义符号

| username: emerson_cai

【TiDB Usage Environment】Production / Testing / PoC
【TiDB Version】
【Reproduction Path】What operations were performed when the issue occurred
【Encountered Issue: Issue Phenomenon and Impact】
【Resource Configuration】Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots / Logs / Monitoring】

select JSON_OBJECT(“icon”,“”,“display”,“ab\c”,“regular_validation_rule”,“^-?[1-9]\d*$”);
This SQL statement automatically removes the underscore, resulting in {“display”: “abc”, “icon”: “”, “regular_validation_rule”: “^-?[1-9]d*$”}

If I use two backslashes, for example: select JSON_OBJECT(“icon”,“”,“display”,“ab\c”,“regular_validation_rule”,“^-?[1-9]\d*$”);
It becomes {“display”: “ab\c”, “icon”: “”, “regular_validation_rule”: “^-?[1-9]\d*$”}

Both of these are incorrect, causing an error in the regular expression. How should this be resolved?

| username: xfworld | Original post link

Just convert it directly to base64 and store it… :rofl:

| username: emerson_cai | Original post link

I found that the forum also added a , causing the message to be inaccurate.

| username: tidb菜鸟一只 | Original post link

SELECT REPLACE(REPLACE(JSON_OBJECT(‘icon’,‘’,‘display’,‘ab\c’,‘regular_validation_rule’,‘^-?[1-9]\d*$’),CONCAT(CHAR(92),CHAR(92)),CHAR(92)), CHAR(92), CONCAT(CHAR(92), CHAR(92)));

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.