Current location - Quotes Website - Signature design - How to optimize long JSON data
How to optimize long JSON data
As we know, JSON, as a lightweight data exchange format, is now widely used, especially in the API layer, and the returned data format is basically JSON. But if the JSON string is too long, it is also time-consuming in network transmission. From the performance point of view, we need to optimize JSON reasonably.

JSON optimization suggestion

1. The server side turns on GZip compression.

Mainstream servers support GZip compression. For ordinary plain text content, the GZip compression rate is above 35%, and the benefits of this are also obvious:

Reduce the JSON output size, and the network transmission speed is faster;

Save bandwidth.

2. Abbreviate key names

As far as the result set is concerned, the data is output by the query cycle, so we shorten the key name and compress the JSON text length in disguise. For example, the original {"name": "Zhang San"} can be written as {"A": "Zhang San"}

3. Chinese in 3.JSON should not be converted into Unicode encoding.

At present, many people like to convert Chinese characters in JSON into Unicode codes, and then the JSON text content will become very long. If we avoid transcoding Chinese characters, we can control the text length.

This is my opinion. What do you think of this problem? Welcome to communicate in the comments section below ~ I am a creator in the field of science and technology and have ten years of experience in the Internet industry. Welcome to follow me to learn more about science and technology!