简体   繁体   中英

JSON_EXTRACT not working for nested json data

I want to select the data from my table which is json data so to show my table data is like this :

user_id:    1

metaname:  mymetaname

meta_value:    a:1:{i:0;a:10:{s:7:"street1";s:36:"shiv plaza";s:4:"city";s:5:"surat";s:5:"state";s:7:"gujarat";s:7:"zipcode";s:6:"395010";s:14:"dollet_country";s:2:"IN";s:10:"tostreet1l";s:5:"surat";s:7:"tocityl";s:5:"surat";s:8:"tostatel";s:5:"surat";s:10:"tozipcodel";s:6:"395000";s:17:"todollet_countryl";s:2:"IN";}}

And i am trying to run this query :

SELECT user_id,JSON_EXTRACT(meta_value, '$."city"') FROM  `usermetatable`

But it's showing error :

[Invalid JSON text in argument 1 to function json_extract: "Invalid value." at position 0.]

My json data in table can not be changed to other and it's correct JSON for sure, Could anyone correct above query ?

That's not JSON data. It looks like a serialized PHP object. See http://php.net/serialize

There's no MySQL function for extracting a field from that serialized object. You should fetch the whole object into a PHP app, and call unserialize() on it, then access the object members.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM