19

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.

5
  • 2
    Try "$.data.\"12\"". Commented Mar 29, 2018 at 13:36
  • Try using the function JSON_CONTAINS. Commented Mar 29, 2018 at 13:37
  • @wchiquito it doesn't work. it consider string ' "12" ' as key Commented Mar 29, 2018 at 13:38
  • This seems to be bug in mysql engine as I'm getting Error: UNKNOWN_CODE_PLEASE_REPORT: here db-fiddle.com/f/bLUtMxWwAH9A2hT7LEaATS/0 Commented Mar 29, 2018 at 14:20
  • @wchiquito it worked like so too. Thanks! Commented Mar 29, 2018 at 15:34

1 Answer 1

23

@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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.