Jovan Popovic has a couple posts showing JSON parsing performance in SQL Server 2017. First up, he makes the statement that JSON parsing can be 10x faster than XML:
I’m running 10000 iterations and getting the average spent time.
Average time to parse JSON and get the value using JSON_VALUE() function is around 3 microseconds while the equivalent action with XML typed variable and value() method takes between 30 and 40 microseconds.
This shows that parsing JSON “plain text” is 10x faster than parsing strongly typed XML variable.
He also compares JSON parsing to spatial type parsing:
I’m running 100.000 iterations and getting the average spent time in both cases. The results are:
- Spatial type needs around 11-14 microseconds to get the X coordinate
- JSON parser needs around 1-2 microseconds to get the value from X property (including CAST to float)
We can see that parsing JSON text is much faster than the equivalent operation in Spatial type.
JSON uses NVARCHAR type that is the most optimized type in SQL Server because it is used in most of the queries in SQL Server. JSON parser is based on T-SQL parser that is also very optimized. Spatial has a type, but it is still some binary serialized object that needs to be deserialized when we need to access the fields. In this case, scanning NVARCHAR is much faster than deserializing binary data into spatial.
On this side, Jovan does note that there are benefits to using spatial types, like performing spatial calculations.