1

I am trying to get the email from the array json, but it returns null value

[
    {
        "name": "Arun", 
        "email": "[email protected]"
    }, 
    {
        "name": "Arun kumar",
        "email": "[email protected]"
    }
]

and my Json query is select json->>"$.name" as email from json

But this query is return null value

5
  • 1
    what kind of syntax it is select json->>"$.name" as email from json? Commented Jun 11, 2019 at 6:18
  • @AlivetoDie its mysql json select query Commented Jun 11, 2019 at 6:19
  • 1
    what about json_decode()? Commented Jun 11, 2019 at 6:30
  • you want to fetch name or email in other words Arun or [email protected]? Commented Jun 11, 2019 at 6:50
  • @ArunRanga, In order to use JSON type in MySQL you must have your MySQL version >= 8.x. Search something in this JSON is very complicated and sometimes not possible. Commented Jun 11, 2019 at 6:51

2 Answers 2

2

I tested the following and worked for me on your json sample

$json='[{"name": "Arun", "email": "[email protected]"}, {"name": "Arun kumar", "email": "[email protected]"}]';
$data=json_decode($json,true);

foreach ($data as $key => $value) {
    echo $value["email"] . "<br>";
}
Sign up to request clarification or add additional context in comments.

Comments

2

This should work,

JSON_EXTRACT(yourstring, '$[*].email')

yourstring - your json data or field in database
$ is json syntax to search json object * means all multidimensional array
email check email in * values

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.