6

Is it possible to use JSON_EXTRACT with integer keys?

I want to extract [273, 140] from below, but the SQL does not work ...

SELECT json_extract('{"1": [273, 140], "2": [273.5, 198.5], "3": [209, 191]}', '$.1');

I am trying to use syntax from https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#operator_json-column-path

I get error:

ERROR 3143 (42000): Invalid JSON path expression. 
The error is around character position 3
1

1 Answer 1

11

You should use double quotes around the key if it is a number. This works:

select json_extract('{"1": [273, 140], "2": [273.5, 198.5], "3": [209, 191]}', '$."1"');
Sign up to request clarification or add additional context in comments.

1 Comment

While this code snippet may solve the question, including an explanation helps to improve the quality of your response. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.

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.