How do i nicely decode Laravel failed jobs JSON

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How do I nicely decode Laravel failed jobs JSON?

How should I decode and "prettify" Laravel's failed-jobs payload?

When working with Laravel queues, a common point of confusion arises when examining the failed_jobs table in your database. The data stored in the payload column often looks less like standard, human-readable JSON and more like a highly compressed, serialized string. This is a design choice made for efficiency, but it requires specific steps to make sense of.

If you are dealing with failed jobs, understanding how Laravel serializes this data is the first step toward effective debugging and monitoring. As experienced developers, we know that database storage needs to be efficient, but that doesn't mean the information stored should be inaccessible.

Understanding the Payload Format: PHP Serialization

The payload you are seeing—which looks like {"job":"Illuminate\\Queue\\CallQueuedHandler@call", "data":{...}}—is not pure JSON; it is a string representation of a serialized PHP object, typically generated using the native PHP function serialize().

This format allows Laravel to store complex data structures (like arrays and nested objects) efficiently within a single database column. When you retrieve this string from your database, it needs to be converted back into a usable PHP structure before it can be truly "decoded."

The key function you need in PHP to reverse this process is unserialize(). This function takes the serialized string and converts it back into the original PHP variable or object format.

Step-by-Step Decoding Process

Decoding this payload involves two main stages: deserialization and prettification (re-encoding).

Step 1: Deserializing the Payload

First, you must retrieve the raw string from your database and use unserialize() to turn it into a native PHP structure.

Here is a conceptual example demonstrating how this might look in a Laravel context (assuming you are fetching the data):

// Assume $serializedPayload is the string retrieved from the failed_jobs table
$serializedPayload = '{"job":"Illuminate\\Queue\\CallQueuedHandler@call","data":{"commandName":"App\\Jobs\\createHostingOncPanel","command":"O:30:\"App\\Jobs\\createHostingOncPanel\":7:{s:10:\"\u0000*\u0000orderNo\";i:11;s:18:\"\u0000*\u0000hostingPackages\";s:45:\"[{\"domainName\":\"qwddqwd.io\",\"hostingType\":1}]\";s:7:\"\u0000*\u0000user\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":2:{s:5:\"class\";s:8:\"App\\User\";s:2:\"id\";i:1;}s:10:\"connection\";N;s:5:\"queue\";N;s:5:\"delay\";N;s:6:\"\u0000*\u0000job\";N;}}';

// Decode the serialized string back into a PHP array/object
$decodedData = unserialize($serializedPayload);

// $decodedData is now a usable PHP variable containing the job details.

Step 2: Prettifying the Data (Converting to Readable JSON)

While unserialize() gives you access to the raw PHP structure, it still doesn't look clean for immediate viewing or external processing. To "prettify" this data—meaning converting it into a standard, readable format like JSON—you simply use json_encode().

// Convert the decoded PHP structure back into a nicely formatted JSON string
$prettyJson = json_encode($decodedData, JSON_PRETTY_PRINT);

echo $prettyJson;

By adding the JSON_PRETTY_PRINT flag to json_encode(), you ensure that the resulting string is neatly formatted with indentation, making it extremely easy for developers or monitoring systems to read and debug the failed job details.

Best Practices for Queue Management

When managing queues and failed jobs in Laravel, remember that robust data handling is crucial. While serialization saves space on disk, always plan for readability when retrieving and debugging information. For complex application architectures, like those built around services managed by Laravel, ensuring that data flows clearly from the database to your application layer is paramount. Always strive for clarity in your data representation, even when using efficient storage methods.

In conclusion, decoding Laravel's failed jobs payload is a simple matter of reversing the serialization process using PHP’s built-in functions. By mastering unserialize() and json_encode(), you can transform cryptic database strings into actionable, readable data, significantly improving your debugging workflow.