json_encode
Returns the JSON representation of a value. Used for serializing PHP data structures to JSON format.
Parameters
main.php
Return Values
string|false
Returns a JSON encoded string on success or false on failure
On success:JSON string representation of the input value
On failure:false if encoding fails (use json_last_error() for details)
Notes
- All string data must be UTF-8 encoded
- Only publicly visible properties are included for objects
- Use flags like JSON_PRETTY_PRINT for formatted output
- Numeric arrays become JSON arrays, associative arrays become JSON objects
Changelog
- 7.3.0: JSON_THROW_ON_ERROR flag added
- 7.2.0: JSON_INVALID_UTF8_IGNORE and JSON_INVALID_UTF8_SUBSTITUTE flags added
Related Functions
json_decode
JSONDecodes a JSON string into a PHP variable (object or array).
jsondecodeapi