1

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 ?

1
  • " it's correct JSON for sure"...what makes you think so? It doesn't look like correct JSON based on that sample, and jsonlint.com (a site you can use to validate your JSON strings) agrees with me. It's quite a long way from being valid JSON, in fact. Commented Jul 16, 2018 at 12:34

1 Answer 1

3

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.

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.