2

I want to use the json_search function in MySQL to query data. But find the search is case-sensitive.

For example:

SET @j = '[{"x":"Abc"}, {"y":"bcd"}]';
SELECT JSON_SEARCH(@j, 'one', 'ABC'); 

This select will return the null. But I need it return "x":"Abc" to me.

Is there any way I can make the search not case-sensitive? So I can get the result $[0].x

Dharman
  • 30,962
  • 25
  • 85
  • 135
DreamFan
  • 21
  • 2
  • Related: [Get path expression of a value inside JSON data using case insensitive search using MySQL Json_search function](https://stackoverflow.com/questions/52988706/get-path-expression-of-a-value-inside-json-data-using-case-insensitive-search-us) – Scratte Aug 04 '20 at 09:09

1 Answers1

4

The trick is to make the JSON lower case before you search it:

SELECT JSON_SEARCH(LOWER(@j), 'one', LOWER('ABC')); 

See dbfiddle.uk for variations.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Scratte
  • 3,056
  • 6
  • 19
  • 26