Reputation: 23
I'm using the JSON_EXTRACT with MYSQL and using this command:
SET @j = '{"id" : "1"}';
SELECT JSON_EXTRACT(@j, '$.id')
the result is
"1"
but, when I use
SET @j = '[{"id" : "1"}, {"id" : "2"}]';
SELECT JSON_EXTRACT(@j, '$.id')
the result is
NULL
I expected this result
"1"
"2"
Any sugestion? I want the list of ID'S from JSON.
Upvotes: 2
Views: 1801
Reputation: 119
try this:
SET @j = '[{"id" : "1"}, {"id" : "2"}]';
SELECT JSON_EXTRACT(@j,'$[*].id')
the result is:
["1", "2"]
Upvotes: 2