15

I have a MySQL table with a JSON column called sent. The entries in the column have information like below:

{
 "data": {
  "12":"1920293"
 }
}

I'm trying to use the mysql query:

select sent->"$.data.12" from mytable

but I get an exception:

Invalid JSON path expression. The error is around character position 9.

Any idea How I can extract the information? The query works fine for non-numeric subfields.

Ibrahim Lawal
  • 1,168
  • 16
  • 31

1 Answers1

19

@Ibrahim, You have an error in your code. If you use number (or spaced words) as key in a JSON data type in MySQL, you'll need to double-quote it.

Therefore, the correct MySQL statement in your case is:

select sent->'$.data."12"' FROM mytable;

Thanks, @JeffreyKilelo

Jeffrey Kilelo
  • 4,444
  • 1
  • 9
  • 6