Overview
This node provides functionality to convert between PHP serialized strings and JSON objects. It supports two main operations:
- PHP Deserialization (反序列化): Converts a PHP serialized string into a JSON object. This is useful when you receive data serialized in PHP format and want to work with it as JSON within n8n.
- PHP Serialization (序列化): Converts JSON data into a PHP serialized string. This is helpful when you need to send or store data in PHP serialized format.
Practical examples:
- Importing data from a PHP-based system that exports serialized strings, then processing it as JSON.
- Preparing JSON data for consumption by a PHP application expecting serialized input.
Properties
| Name | Meaning |
|---|---|
| 操作 (operation) | Choose the operation: "PHP 反序列化" (unserialize) to convert PHP serialized string to JSON, or "PHP 序列化" (serialize) to convert JSON to PHP serialized string. |
| PHP 序列化字符串 | The PHP serialized string to be deserialized (only shown when operation is "PHP 反序列化"). |
| JSON 数据 | The JSON data to be serialized into PHP format (only shown when operation is "PHP 序列化"). |
Output
The output is always a JSON object with the following structure depending on the operation:
For PHP 反序列化 (unserialize):
{ "success": true, "operation": "unserialize", "result": <deserialized JSON object or value>, "fullData": <full deserialized data> }resultcontains the main extracted data (optionally filtered by a path if implemented).fullDatacontains the entire deserialized PHP data structure.- If an error occurs during deserialization, the output will be:
{ "success": false, "operation": "unserialize", "error": "<error message>" }For PHP 序列化 (serialize):
{ "success": true, "operation": "serialize", "result": "<PHP serialized string>", "originalData": <original JSON object> }resultis the PHP serialized string generated from the input JSON.originalDataechoes back the input JSON.- On serialization error, the output will be:
{ "success": false, "operation": "serialize", "error": "<error message>" }
The node does not output binary data.
Dependencies
- Uses the external library
php-serializeto perform serialization and deserialization of PHP data. - No special credentials or environment variables are required.
Troubleshooting
- Common issues:
- Invalid PHP serialized string format can cause deserialization errors.
- Malformed JSON input will cause serialization to fail.
- Error messages:
- Errors during unserialization or serialization are caught and returned in the output's
errorfield. - To resolve errors, verify that the input PHP serialized string or JSON data is correctly formatted.
- Errors during unserialization or serialization are caught and returned in the output's
- The node supports continuing on failure if enabled, allowing workflows to handle errors gracefully.
Links and References
- php-serialize npm package – Used for PHP serialization/deserialization.
- PHP serialize() function
- PHP unserialize() function