I have this json from my database and I want to extract one value from it:
{"uuid":"3ed79fdc-6ef0-441b-b9b0-525eeaebf183","displayName":"App\\Jobs\\SendReport","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries":null,"maxExceptions":null,"failOnTimeout":false,"backoff":null,"timeout":null,"retryUntil":null,"data":{"commandName":"App\\Jobs\\SendReport","command":"O:19:\"App\\Jobs\\SendReport\":11:{s:12:\"\u0000*\u0000tableName\";s:9:\"employees\";s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"}}
If I use a tool online to visualize jsons, it looks like this:
Then, first i want print the json using "print_r()" function of php and I can't I don't know why.
it does not return any value.
$string = '{"uuid":"3ed79fdc-6ef0-441b-b9b0-525eeaebf183","displayName":"App\\Jobs\\SendReport","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries":null,"maxExceptions":null,"failOnTimeout":false,"backoff":null,"timeout":null,"retryUntil":null,"data":{"commandName":"App\\Jobs\\SendReport","command":"O:19:\"App\\Jobs\\SendReport\":11:{s:12:\"\u0000*\u0000tableName\";s:9:\"employees\";s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"}}';
$payload = json_decode($string, true);
//print the json
print_r($payload);
//nothing happnes
//extract the table name:
$command = unserialize($payload['data']['command']);
echo $command->tableName;
//can't access to tableName property.
is possible extract that value from the json? please guys if you have any idea I will apreciate it. I'm using json_decode to transform that string to decode the json string and then I'm trying to access to one property and get the tableName 'employees' and I can't.
This is another payload but the table name is "departments":
$string = '{"uuid":"8c4640de-599c-4795-bffe-b043cf74a226","displayName":"App\\Jobs\\SendReport","job":"Illuminate\\Queue\\CallQueuedHandler@call","maxTries":null,"maxExceptions":null,"failOnTimeout":false,"backoff":null,"timeout":null,"retryUntil":null,"data":{"commandName":"App\\Jobs\\SendReport","command":"O:19:\"App\\Jobs\\SendReport\":11:{s:12:\"\u0000*\u0000tableName\";s:11:\"departments\";s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"}}';
Here the key before 'departments' is s:11 in the first payload of which contains 'employees' there is a different key called s:9 I would like to know how get this value.
Thanks so much.
This value is a mix of JSON and another form of serialization, which can be created with serialize() function. You can decode it by its opposite - unserialize().
Try to decode JSON first and then to unserialize thatcommand
value (still assuming it's WordPress):
$json = '{"uuid":"3ed79fdc-6ef0-441b-b9b0-525eeaebf183","displayName":"App\\\Jobs\\\SendReport","job":"Illuminate\\\Queue\\\CallQueuedHandler@call","maxTries":null,"maxExceptions":null,"failOnTimeout":false,"backoff":null,"timeout":null,"retryUntil":null,"data":{"commandName":"App\\\Jobs\\\SendReport","command":"O:19:\"App\\\Jobs\\\SendReport\":11:{s:9:\"tableName\";s:9:\"employees\";s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"}}';
$item = json_decode($json);
$command = unserialize($item->data->command);
var_dump($command); // what's there?
tableName
is a protected property, so I'm guessing you have a method to read it in yourApp\Jobs\SendReport
class.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.