2

How do I access the value of a object property, inside an array, using JSON_QUERY in MariaDB? I have a JSON field with following data, and want to access the value of the section property.

[
  [
    {"section": "search"}
  ]
]

The following SQL is returning NULL

SELECT JSON_QUERY('[[{"section": "search"}]]', '$[0][0].section') FROM mytable
Joyce Babu
  • 19,602
  • 13
  • 62
  • 97

1 Answers1

4

For anyone else having the same issue, you have to use JSON_VALUE for accessing scalar values. The following query gives the expected result.

SELECT JSON_VALUE'[[{"section": "search"}]]', '$[0][0].section') FROM mytable;

JSON_QUERY vs JSON_VALUE

Joyce Babu
  • 19,602
  • 13
  • 62
  • 97