[MDEV-20365] JSON_VALID and any JSON function doesnt work correctly whe there is a double-quote char (escaped) inside a value in a complex json array (more tha 2 elements) Created: 2019-08-16  Updated: 2019-08-16  Resolved: 2019-08-16

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: 10.3.17, 10.4.7
Fix Version/s: N/A

Type: Bug Priority: Trivial
Reporter: Francisco Dueñas Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: JSON, JSON_VALID, quotes
Environment:

Windows 10 64 bit



 Description   

Still 10.3.17. any JSON function will return NULL when there is a quoted char in a complex JSON array. Witth a Json single element array there is no problem:

Tests:
Phrase: Venture "Extended" Edition

  1. SELECT JSON_QUOTE('Venture "Extended" Edition');
    Returns: "Venture \"Extended\" Edition"
  2. SELECT CONCAT('[ {"Year":1999,"Make":"Chevy","Model":', JSON_QUOTE('Venture \"Extended\" Edition'),'}

    ]') INTO @_json;
    SELECT JSON_VALID(@_json), JSON_LENGTH(@_json);
    Returns 1 and 1 (for a single element there is no problem)

  3. SELECT '[ {"Year":1997,"Make":"Ford","Model":"E350","Description":"ac, abs, moon","Price":3000,"UpForSale":"2017-10-01"}

    ,

    {"Year":1999,"Make":"Chevy","Model":"Venture Extended Edition","Description":null,"Price":4900,"UpForSale":"2017-10-03T12:15"}

    ]' INTO @_json;
    SELECT JSON_VALID(@_json), JSON_LENGTH(@_json);
    Returns 1 and 2

  4. SELECT '[ {"Year":1997,"Make":"Ford","Model":"E350","Description":"ac, abs, moon","Price":3000,"UpForSale":"2017-10-01"}

    ,

    {"Year":1999,"Make":"Chevy","Model":"Venture \"Extended\" Edition","Description":null,"Price":4900,"UpForSale":"2017-10-03T12:15"}

    ]' INTO @_json;
    SELECT JSON_VALID(@_json), JSON_LENGTH(@_json);
    Returns 0 and null

  5. SELECT CONCAT('[ {"Year":1997,"Make":"Ford","Model":"E350","Description":"ac, abs, moon","Price":3000,"UpForSale":"2017-10-01"}

    ,',
    '

    {"Year":1999,"Make":"Chevy","Model":', JSON_QUOTE('Venture \"Extended\" Edition'),'"Description":null,"Price":4900,"UpForSale":"2017-10-03T12:15"}

    ]') INTO @_json;
    SELECT JSON_VALID(@_json), JSON_LENGTH(@_json);
    Returns 0 and null



 Comments   
Comment by Francisco Dueñas [ 2019-08-16 ]

Sorry found there a mistake in my sql senteces. This bug can be closed safely

Comment by Alice Sherepa [ 2019-08-16 ]

yes, comma, it happens

MariaDB [(none)]> SELECT CONCAT('[ {"Year":1997,"Make":"Ford","Model":"E350","Description":"ac, abs, moon","Price":3000,"UpForSale":"2017-10-01"},', '{"Year":1999,"Make":"Chevy","Model":', JSON_QUOTE('Venture \"Extended\" Edition'),',"Description":null,"Price":4900,"UpForSale":"2017-10-03T12:15"}]') INTO @_json;
Query OK, 1 row affected (0.000 sec)
 
MariaDB [(none)]> SELECT JSON_VALID(@_json), JSON_LENGTH(@_json);
+--------------------+---------------------+
| JSON_VALID(@_json) | JSON_LENGTH(@_json) |
+--------------------+---------------------+
|                  1 |                   2 |
+--------------------+---------------------+
1 row in set (0.000 sec)

Generated at Thu Feb 08 08:58:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.