Reputation:
I'm working on a project where I ideally need to return a JSON object in an HTTP response where one field points to an xml snippet as a value. The object would look something like the following.
{
"driver1_url" : "https://driver.url.download.link",
"driver2_url" : "https://driver2.url.download.link",
"xml_snippet" : "<xml><snippet>value</snippet></xml>"
}
The xml snippet could be pretty long. Is it considered bad practice to embed XML into a JSON object? And if so, is there a better way to achieve what I've described?
Upvotes: 2
Views: 1718
Reputation: 320
It's not "bad" to add an XML string as a JSON value. It's only inconvenient if other programmers have to use your JSON response, because now they'd need an XML parser in addition to JSON abilities in their own programs. If you're the only one using JSON with XML values, then go ahead, have fun. It's your project, there's no wrong way to use these interchange formats so long as it works for your project and there's no expected need for compatibility with other systems.
If best practices are your concern, though, it is ideal to use either strict JSON or strict SOAP (the XML sibling of JSON, so to speak) for maximum compatibility.
Upvotes: 1