Advertisement
Advanced SQL Server, XML Data Type & Querying

How would you decide between using the XML data type and the JSON functions available in SQL Server for a new project that needs to store semi structured data?

Short answer

You would generally choose JSON for new development if your application and its consumers primarily work with JSON already, since it is more lightweight and widely used in modern web applications, while XML remains a reasonable choice if you need features like formal schema…

Save SQL Server mock interview
Advertisement
AModel answer
You would generally choose JSON for new development if your application and its consumers primarily work with JSON already, since it is more lightweight and widely used in modern web applications, while XML remains a reasonable choice if you need features like formal schema validation, are integrating with existing systems that already use XML, or need XML specific querying capabilities like XQuery.
-- JSON tends to be the more common choice for new applications
-- integrating with modern web based systems
SELECT JSON_VALUE(ProductDetailsJson, '$.name') FROM Products;
Real-world example
A team building a new e-commerce platform chooses JSON over XML for storing flexible product attributes, since their application's front end and API already work natively with JSON, making XML an unnecessary added complexity.
Likely follow-ups
  • What specific capabilities does XML offer that JSON does not currently support in SQL Server?
  • Is it common to need to support both XML and JSON in the same system?
Related topics