JavaScript - is it possible to use Base122 to send file data in JSON?
As in the question, I want to optimize data transmission in my REST API based on JSONs by replacing Base64 into Base122 in files data case.
Is it possible to make it working?
The answer is: NO.
Bytes encoded with Base122 contains characters that are not allowed directly in JSONs. By using additional escape operation we are able to use Base122 in JSON but it increases text size again which defeats the purpose.
By using Base64 + UTF-8 encoding + gzip/deflate/br/zstd compression we are able to get not perfect but enought effect on data transmission.
As alternative you can use gRPC, WebSockets, BSON or some other binary method of data transmission.
Base122 is unsafe for JSONs.
You can cosinder to use Base94 instead of Base122.
Base94 is more optimal than Base64, so it is good replacemant:
Base64 data is bigger than raw bytes about 33.88%
Base94 data is bigger than raw bytes about 22.24%
Base64 data is bigger than Base94 data about 9.52%
Here you can find proposal for Base94 encoding:
https://dirask.com/snippets/JavaScript-JSON-Base94-encoding-and-decoding-DNO7rp