2

I have a json and i want to extract the value by a key. Not sure how I can implement it. Any suggestion is appreciated.

set @JSON = 
'[
{
    "key": "address",
    "value": "xxx"
},
{
    "key": "addr_lng",
    "value": 100.22
},
{
    "key": "addr_lat",
    "value": 300.22
}
]';

I want to extract the value by key addr_lat, but don't want change the json structure.

300.22
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
xavierzhao
  • 780
  • 9
  • 18

1 Answers1

-2

Try this

SELECT JSON_EXTRACT('{"address": xxx, "addr_lng": 100.22, "addr_lat": 300.22}', '$.addr_lng') AS 'result';

https://database.guide/json_extract-return-data-from-a-json-document-in-mysql/

Suraj
  • 363
  • 2
  • 16