Compressing JSON data for SQL server, best way?
Hi, What's a good way to approach compressing big JSON data and storing it in SQL server? (libraries etc)
11 Replies
you probably want to desterilize your json into an object
and then what?
depends if you want to use something like dapper or efcore, or if you just feed the data by hand into some sql client
at work we serialize it to protobuf
so it's just some bytes
pretty compact
Can you then compress the protobuf output to make it even smaller?
I would try not compress the JSON data. Insert it as it is as JSON. SQL server has built in JSON support to query that data. If you compress the data before inserting it, SQL server is not able to query information out of the JSON data structure. It can only retrieve the full compressed blob.
This fully depends on your requirements.
Example (from https://learn.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-ver16):
SQL server also has build in support for compress/decompress. Check article https://techcommunity.microsoft.com/t5/sql-server-blog/storing-json-in-sql-server/ba-p/384576
What is your requirement for compression? Faster transport, DB space, ...?
Work with JSON data - SQL Server
JSON data in SQL Server
TECHCOMMUNITY.MICROSOFT.COM
Storing JSON in SQL Server
First published on MSDN on Nov 23, 2015 SQL Server offers built-in functions for processing JSON text data. In this post, we will see how you can store JSON in SQL Server database. Problem Various systems, service, loggers, format information in JSON format. This text should be stored in databas...
@RiffTheRaff db space
I achieved half the size using brotli and it works for json input and output
Seeing if I can make that even less
so is db space a major concern?
@AntonC well I’ll be dealing with large json files soon so yeah
you can just store the files too
on disk
it's already really small
many times smaller than json