Brotli compression for JSON producing newlines - any work around?
I am running ASP.NET 7.0 and I don't want to use Newtonsoft because I would have to downgrade.
Can I minify a JSON string without it?
31 Replies
what does minify mean here
like
remove whitespaces & new lines on it @Jayy
the brotli compression algorithm i'm using doesn't interpret new lines well so when decompressing my angular frontend can't read it
this is the default output
wdym
stj outputs json with no spaces and no newlines by default
Jayy#6249
REPL Result: Success
Result: string
Compile: 417.071ms | Execution: 65.127ms | React with ❌ to remove this embed.
maybe i should rephrase the question
i'm using this
https://khalidabuhakmeh.com/compress-strings-with-dotnet-and-csharp
@Jayy to compress my json string
the issue is that the response is this:
\n
everywhere
and newlines everywhere
i thought minifying would fix it but \n
is not a part of json
i tried maybe converting to base64 before compression
and then converting back to string after decompression
but that produced a bunch of errorsCan you use $paste to show your actual program?
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Minimal program that reproduces the issue
So this has nothing to do with json and everything to do with ur compression algorithm lol
absolutely
GitHub
RequestConverter/RequestController.cs at master · OEvans117/Request...
Convert request bundles from Fiddler, Wireshark etc into clean, readable code. Current support for C# & Python - RequestConverter/RequestController.cs at master · OEvans117/RequestConverter
yeah
phrased the question wrong, sorry
Um...what the heck are these awaits?
(Not that that's relevant to your question...)
😵💫
didn't even have a look
it's from the article, i just copy pasted
xD
This compression code shouldn't be using async at all
It's purely in-memory
true
ok.
i figured out the issue
for some reason i was serializing the conversionresult here
var CompressedResult = await Compression.ToBrotliAsync(ConversionResult ,CompressionLevel.SmallestSize);
conclusion i am dumb
thanks for taking a look anyway. @mtreit much appreciatedHmm, I didn't quite understand your conclusion about what the issue is - it's related to that gzip code?
well
when compressing the string (which was already json)
i reserialized it
and i don't know why i did that
and as soon as i fixed that it seemed to work
Your original input json that you re-serialized must have had newlines in it
it did yes
Oh ok, now I understand
are you actually an ms employee ? @mtreit
So minimal repro:
I am, yes.
that's really cool, i can't imagine how you have time on your hands to be helpful here
I'm pretty good at multi-tasking 🙂
Also it gives me something to do when I'm waiting for a build to finish or that kind of thing...
hahah