Languages

JavaScript - is it possible to use Base122 to send file data in JSON?

12 points
Asked by:
Jun-L
963

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?

2 answers
9 points
Answered by:
Jun-L
963

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.

0 comments Add comment
3 points
Answered by:
Jun-L
963

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

0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join