JMSSerializer vs json_encode

What is the benefit of JMSSerializer to convert data to json rather than simply using json_encode? The same question about Zend-Json?

None, really. They’re just convenience wrappers. The benefit is that you can plug and interchange these converters to get from one format to the other, but for purely turning stuff into json, json_encode is perfectly enough.

Is it possible to convert json directly to xml using jmsserializer and vice versa or first should I deserialize data then convert it to another fomat?

If I had one reason why to use this library was the convertion ability between json and xml. But I see its xml format configuration is only documented with annotation within entity classes but I wanted to use only standalone arrays so I cannot use entity annotation but instead i should use its class methods to format my xml but this is not documented, this is why I searched for XMLParser. Since I cannot use its xml feature, there is no reason for me to use this library vs json_encode at all…

I’m not sure what you need exactly. There’s little to no overhead in using any of those solutions, so I suggest you just try them out and see what works best. One of those might very well be the perfect fit, but it depends on your use case and needs.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.