Best SQL Datatype for JSON – Performance and Efficiency

datatypesjsonperformanceperformance-tuningsql serversql-server-2016

In SQL Server 2016, I believe the best datatype for handling JSON is nvarchar.
Most of our JSON strings will not use more than 100 characters.
Should I use nvarchar(100) or nvarchar(max)?

We prefer nvarchar(100). I just want to make sure the new JSON functions do not have a preference for using the max type. Max is stored outside of row and slightly less efficient performance-wise.

Best Answer

The documentation you linked to links to the JSON page, which says:

JSON is a textual format so the JSON documents are can stored in NVARCHAR columns in SQL Database.

Wait a second...I think this documentation needs a pull request :)

Anyways...As always with MAX, if you don't need it, don't use it! You're correct that it will cause a (slight) performance hit and SQL Server in no way prefers NVARCHAR(MAX) for JSON storage. Consider yourself lucky you're storing such small JSON.