Compressing a string to upload into a field of the JSON object

Asked

Viewed 393 times

2

Hello,

I am developing a java API, which returns a json object.

One of the final json fields is long text, of unknown dimension. Text may or may not contain special characters.

I am sending the raw information, in a string. But as the dimension is unknown, I am afraid it exceeds the acceptable. Some way to compress that information?

I can send the converted string to an array of bytes, any client-side language/platform can get the original string?

The text can be the size of a multi-page document. Who knows an entire book...

Thank you.

  • Which server window or linux?

2 answers

1

I do not know how it is in practice, because I am not used to windows, but maybe you can increase the limit of your publication, so there will be no interruptions in the sending process:

On the linux server, just set the limits in php.ini or php .htaccess:

post_max_size 800M
upload_max_filesize = 800M

In Windows I think it’s something similar to this on the web.config:

<configuration>
  <system.web>
    <httpRuntime maxUrlLength="8000" />
  </system.web>
</configuration>

Now if you want to compress json, you can use a library for this: example

1

I’ll assume you’re working with a REST service.

I wouldn’t worry about compacting the string in hand.

Instead I’d make sure the server supports Content-Encoding so the customer can make the query and receive the compressed data. The vast majority of HTTP communication libraries support seamless decompression and browsers as well.

  • The service is a java Servlet that returns a json object. Built with the help of the GSON lib. Therefore, in practice it is not a Restfull service. How to enable/certify Content_encoding support on the server side?

  • Enough to define Sponse.setHeader("Content-Encoding", "gzip"); in Servlet?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.