using System.IO.Compression;
string json = "{\"RequestParams\":{\"RequestHeader\":\"[{\\\"Key\\\":\\\"cache-control\\\",\\\"Value\\\":[\\\"no-cache\\\"]},{\\\"Key\\\":\\\"Accept\\\",\\\"Value\\\":[\\\"application/json\\\"]}]\",\"RequestBodyJson\":\"null\",\"RequestUrl\":\"partner/orders/937-FEB96FA-A315B6AB80C9/cancellation/\"},\"ResponseMessage\":\"{\\\"Version\\\":{\\\"Major\\\":1,\\\"Minor\\\":1,\\\"Build\\\":-1,\\\"Revision\\\":-1,\\\"MajorRevision\\\":-1,\\\"MinorRevision\\\":-1},\\\"Content\\\":{\\\"Headers\\\":[{\\\"Key\\\":\\\"Content-Length\\\",\\\"Value\\\":[\\\"463\\\"]},{\\\"Key\\\":\\\"Content-Type\\\",\\\"Value\\\":[\\\"application/json\\\"]}]},\\\"StatusCode\\\":200,\\\"ReasonPhrase\\\":\\\"OK\\\",\\\"Headers\\\":[{\\\"Key\\\":\\\"Connection\\\",\\\"Value\\\":[\\\"keep-alive\\\"]},{\\\"Key\\\":\\\"Access-Control-Allow-Origin\\\",\\\"Value\\\":[\\\"*\\\"]},{\\\"Key\\\":\\\"X-Frame-Options\\\",\\\"Value\\\":[\\\"DENY\\\"]},{\\\"Key\\\":\\\"X-Content-Type-Options\\\",\\\"Value\\\":[\\\"nosniff\\\"]},{\\\"Key\\\":\\\"Strict-Transport-Security\\\",\\\"Value\\\":[\\\"max-age=31536000;includeSubDomains;preload\\\"]},{\\\"Key\\\":\\\"Cache-Control\\\",\\\"Value\\\":[\\\"no-cache,private\\\"]},{\\\"Key\\\":\\\"Date\\\",\\\"Value\\\":[\\\"Thu,06Feb202522:19:57GMT\\\"]},{\\\"Key\\\":\\\"Server\\\",\\\"Value\\\":[\\\"nginx\\\"]}],\\\"RequestMessage\\\":{\\\"Version\\\":{\\\"Major\\\":1,\\\"Minor\\\":1,\\\"Build\\\":-1,\\\"Revision\\\":-1,\\\"MajorRevision\\\":-1,\\\"MinorRevision\\\":-1},\\\"Content\\\":{\\\"Headers\\\":[{\\\"Key\\\":\\\"Content-Type\\\",\\\"Value\\\":[\\\"application/json;charset=utf-8\\\"]},{\\\"Key\\\":\\\"Content-Length\\\",\\\"Value\\\":[\\\"4\\\"]}]},\\\"Method\\\":{\\\"Method\\\":\\\"POST\\\"},\\\"RequestUri\\\":\\\"https://gateway.battleface.com/api/partner/orders/937-FEB96FA-A315B6AB80C9/cancellation/\\\",\\\"Headers\\\":[{\\\"Key\\\":\\\"Authorization\\\",\\\"Value\\\":[\\\"BearereyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIwYjFmMzcyZi0wMTE2LTQ1NzEtYTYxYy1jMGZmODhkNTJhM2MiLCJqdGkiOiI5MTI5MGNiMTllZWJiMTNjNjE0ZWE2YzRjNDdiNTgwYTNhODAxOTBlMjhjMWMwMjI5Mzk2MWZmZTQ5YmJiMTc4YmNhNTU1ZDUwYzE5YzU3MCIsImlhdCI6MTczMjIwMjk0Mi42Nzg2MjgsIm5iZiI6MTczMjIwMjk0Mi42Nzg2MzIsImV4cCI6NDg4Nzg3NjU0Mi42MzY5OSwic3ViIjoiZTRkOTBhM2EtYmY3MS00ZTE0LTgyMWEtNmY1ZGU3NmM2MTYyIiwic2NvcGVzIjpbXSwiZGV0YWlscy5pc19zYW5kYm94IjoxfQ.dE_BtvgUG2qE53Z9QVPRtComl2qSzzj9Es5KpDaxevgj2mJ1X3F1WQ6EuyWl4UHo8T2ohtSwJsz4S8RDTQbQMWi3XO7rFd8nBhROPB5WEJ5E4p1AZEQg5npIlBeXtCV1Vox9JdKMRY7VfKgWaTMcFZZfp-GR_X_b1QdEWyMODGsgMZiDYksVDytNJB7s_FwfHNqSJnu0jz_2IhgKfkCFPIOlSJNRByueIsqNeVlCQJCOai_yHQYQtmcDxs0cdg3q4IukbeDbXKx1UpzkxA4p8CzAWi0x54I4Jlgt5I70uiJD5SVoxgv17SrnmIV-dHpyMh5_JSnCHapBREKQXkZ51i7M6gqTKK8g4kg4yDFQp7KOM9FB3t-A-4VNB8ZhMDaz_8v3KPK6kFV-6nGoZPTcZvl0Ha05bl4nST7hA0at7wgW7NRLOjrZJ8EjNAjqHZ3qg5XegSmZyGJAOVVoGYswZ-TW7CekioXTIvzT-ftfTszvA5DpIg5d-Qi111X5QbNpCqfrYWzR8mimpTFT64pgQWhjRUS66i3UwW9S7dY-CAG_ef_XzIpCtoiuB8m4U-7H1EbHnaTEGoHlul6D-UAR0so51yNXwFDCbvXHsqJskLiFwuXQzqUUXkvPYfBebc2qyXifVKOOHv6A3wI556Jem1eoXJJuT169jjRyUqh8D7c\\\"]},{\\\"Key\\\":\\\"cache-control\\\",\\\"Value\\\":[\\\"no-cache\\\"]},{\\\"Key\\\":\\\"Accept\\\",\\\"Value\\\":[\\\"application/json\\\"]}],\\\"Properties\\\":{}},\\\"IsSuccessStatusCode\\\":true}\",\"ResponseHeaders\":{\"Connection\":\"keep-alive\",\"Access-Control-Allow-Origin\":\"*\",\"X-Frame-Options\":\"DENY\",\"X-Content-Type-Options\":\"nosniff\",\"Strict-Transport-Security\":\"max-age=31536000;includeSubDomains;preload\",\"Cache-Control\":\"no-cache,private\",\"Date\":\"Thu,06Feb202522:19:57GMT\",\"Server\":\"nginx\"}}";
byte[] originalBytes = Encoding.UTF8.GetBytes(json);
Console.WriteLine($"Original Size: {originalBytes.Length} bytes");
byte[] gzipCompressed = CompressGZip(json);
Console.WriteLine($"GZip Compressed Size: {gzipCompressed.Length} bytes");
byte[] deflateCompressed = CompressDeflate(json);
Console.WriteLine($"Deflate Compressed Size: {deflateCompressed.Length} bytes");
string gzipDecompressed = DecompressGZip(gzipCompressed);
string deflateDecompressed = DecompressDeflate(deflateCompressed);
Console.WriteLine($"\nDecompressed JSON matches original (GZip): {json == gzipDecompressed}");
Console.WriteLine($"Decompressed JSON matches original (Deflate): {json == deflateDecompressed}");
Console.WriteLine(deflateDecompressed);
static byte[] CompressGZip(string data)
byte[] bytes = Encoding.UTF8.GetBytes(data);
using (var output = new MemoryStream())
using (var gzip = new GZipStream(output, CompressionMode.Compress, true))
gzip.Write(bytes, 0, bytes.Length);
static string DecompressGZip(byte[] compressedData)
using (var input = new MemoryStream(compressedData))
using (var gzip = new GZipStream(input, CompressionMode.Decompress))
using (var output = new MemoryStream())
return Encoding.UTF8.GetString(output.ToArray());
static byte[] CompressDeflate(string data)
byte[] bytes = Encoding.UTF8.GetBytes(data);
using (var output = new MemoryStream())
using (var deflate = new DeflateStream(output, CompressionMode.Compress, true))
deflate.Write(bytes, 0, bytes.Length);
static string DecompressDeflate(byte[] compressedData)
using (var input = new MemoryStream(compressedData))
using (var deflate = new DeflateStream(input, CompressionMode.Decompress))
using (var output = new MemoryStream())
return Encoding.UTF8.GetString(output.ToArray());