I have here an object and one of its properties is a DateTime object. Now I want to use Json::serialize() to get the JSON representation of it. Is there a way to instruct Json::serialize() to get the DateTime object as a string? The idea is that automatically ->format('c') would be called on the DateTime object.
You can ignore laminas-json, it was a good solution in the past because it provided a fallback:
ext/json
By default, the above two calls will proxy to the json_decode() and json_encode() functions of ext/json, which is bundled in default installations of PHP. Using laminas-json, however, ensures that the functionality works regardless of whether or not the extension is available. Additionally, the component provides some features not found in ext/json, such as encoding native JSON expressions, communicating class inheritance, and customizations around pretty printing.