TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: JSON vs. XML?

3 pointsby galazzahalmost 9 years ago
Do you prefer JSON or XML? Why?

6 comments

niftichalmost 9 years ago
For what purpose? Document specifications, data serialization, schema-ful data?<p>JSON&#x27;s data model lines up much better with common data structures in programming languages, while the often-maligned child-element vs. attribute distinction in XML makes a lot of sense to me to distinguish between globally relevant metadata (attributes) vs. data that can stand on its own (elements).<p>When HTTP APIs started winning out at the expense of SOAP or XML-RPC APIs, JSON became preferred because there was no schema to validate and a client could just parse out the fields they were interested in and ignore the rest.<p>Nowadays, more and more deployments add a JSON Schema, officially discouraging that practice and negating one unique differentiator it had versus XML. They&#x27;re both text-based formats you have to parse, and for internal, non-outward-facing purposes I&#x27;d rather use a binary serialization format instead for compactness and because I control both endpoints.<p>My other preferences are, for outward-facing purposes (like a HTTP API return payload), a custom mediatype based on JSON or XML (in that order, because JSON has more community goodwill); for configuration files, neither because the&#x27;re both awful to type in a line-oriented setting; and for protocol or file-format type things that could conceivably stand on their own and be called a &#x27;document&#x27; (like a self-contained file at rest), XML or binary because they allow strongly typed, well-specified formats with less developer effort -- not JSON.
alistproducer2almost 9 years ago
Trying to get that Karma up, huh? I&#x27;ll bite and help you out a bit. I would think the only reason to use XML in a new project would be because it has a schema and you may need your objects &quot;strongly typed.&quot; In days past there also wasn&#x27;t very good support for JSON in C# and other enterprise languages so that extended the XML lifetime.<p>Most times you&#x27;re using XML now it&#x27;s to integrate with a piece of legacy software. Now that most enterprise platforms have good support for JSON, outside of a few special use cases most projects are just going to go with JSON for the convenience of it (no crazy parsers to deal with).
xor_nullalmost 9 years ago
Depends on what you need&#x2F;want to achieve. One nice thing about XML is that you can use XQuery and XSLT for querying&#x2F;document transformation.
WorldMakeralmost 9 years ago
Both? They each have different use cases where they can be more efficient&#x2F;easier to work with.<p>If you are designing a REST API, pay attention the HTTP Accept header and return whichever the client asks for.
HoopleHeadalmost 9 years ago
TOML #because it allows comments<p><a href="https:&#x2F;&#x2F;github.com&#x2F;toml-lang&#x2F;toml" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;toml-lang&#x2F;toml</a>
dozziealmost 9 years ago
For what?