JSON-based interface data coding method and system
Through the encoding method of feature extraction and de-rearrangement of JSON data during JSON data transmission, the network burden problem during large data volume JSON interactive data transmission is solved, and the effect of reducing network congestion risk and improving system throughput is achieved.
Patent Information
- Application Number
- CN202411490027.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-10-24
AI Technical Summary
When large amounts of JSON interactive data or resource interfaces with extremely high request frequency are transmitted, it is easy to increase the network burden, which may cause network congestion and affect the normal use of the service.
A JSON-based interface data encoding method and system is provided. By performing feature extraction and de-rearranging of JSON data at the sending end, encoded JSON data, and decoded on the receiving end to obtain the original JSON data. The method includes two encoding methods, namely the first encoding method and the second encoding method, and the subscript format of the JSON key and value is replaced, thereby reducing the amount of data.
Through the encoded data transmission, the amount of original data is much reduced, which can reduce the transmission pressure, reduce the risk of network congestion, and improve the system throughput.
Smart Images

Figure CN119484170A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data interaction, and in particular to a JSON-based interface data encoding method and system. Background Art
[0002] The separation of front-end and back-end has become a trend in network service development. A large number of applications that use RESTful API interfaces and unified JSON data returns have been deployed and used. That is, the front-end and back-end interact through a large amount of JSON data, and MQTT publish and subscribe messages also use a large amount of JSON data for interaction. That is, for large amounts of JSON interactive data, or resource interfaces with extremely high request frequencies, it will cause a certain burden on accessing the network, which may cause network congestion and affect the normal use of services.
[0003] The network burden when transmitting data in large amounts of JSON interactive data or resource interfaces with extremely high request frequencies is a technical problem that needs to be solved. Summary of the invention
[0004] The technical task of the present invention is to address the above shortcomings and provide a JSON-based interface data encoding method and system to solve the technical problem of network burden when transmitting data in large amounts of JSON interactive data or resource interfaces with extremely high request frequencies.
[0005] In a first aspect, the present invention provides a JSON-based interface data encoding method, which is applied to a sending end and a receiving end, and the method comprises the following steps:
[0006] The client as the sending end requests the original JSON data, calls the encoding interface, encodes the original JSON data through the encoding method built into the encoding interface, encodes the JSON data by extracting features and de-repeating the JSON data, obtains the encoded JSON data, and sends the encoded JSON data to the server as the receiving end, wherein the encoded JSON data includes the encoding tag and the feature list;
[0007] After receiving the encoded JSON data, the server calls the decoding interface and decodes the encoded JSON data through the built-in decoding method of the decoding interface. According to the encoding tag and feature list, the original JSON data is obtained from the encoded JSON data, and the decoded original JSON data is sent to the relevant service interface.
[0008] Preferably, encoding is performed by extracting features and removing duplicates from JSON data, including two encoding methods, namely a first encoding method and a second encoding method;
[0009] The first encoding method includes the following steps: extracting a JSON key string from the original JSON data, and de-duplicating the extracted JSON key string into a JSON array, converting the subscript of the array where the JSON key string is located from a numeric format to a string format, and replacing the original key string with the subscript in the string format, obtaining a feature list, and adding encoding annotations to generate an encoded string, and sending the encoded string and the JSON data as encoded JSON data to a receiving end;
[0010] The second encoding method includes the following steps: for the original JSON data, extract the JSON key string and value string, and deduplicate the extracted JSON key string and value string and arrange them into a JSON array, convert the subscript of the array where the JSON key string and value string are located from a numeric format to a string format, and replace the original key string with the subscript in the string format to obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
[0011] Preferably, for the first encoding method, the JOSN data and the encoded string are sent to the server through the original interface, or the JOSN data is sent to the server through the original interface and the encoded string is sent to the server through a separate interface;
[0012] For the second encoding method, the encoded JOSN data and the encoded string are sent to the server through the original interface, or the encoded JOSN data is sent to the server through the original interface and the encoded string is sent to the server through a separate interface.
[0013] Preferably, for the first encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the key string in the encoded JSON data is replaced with the string in the feature list to generate the original JSON data;
[0014] For the second encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the key string and the value string in the encoded JSON data are replaced with the strings in the feature list to generate the original JSON data.
[0015] In a second aspect, the present invention provides a JSON-based interface data encoding system, which is used to encode interface data using a JSON-based interface data encoding method as described in any one of the first aspects, and the system includes a sending end and a receiving end;
[0016] The sending end is used to perform the following operations: request the original JSON data, call the encoding interface, encode the original JSON data through the encoding method built into the encoding interface, encode the JSON data by extracting features and de-repeating the JSON data, obtain the encoded JSON data, and send the encoded JSON data to the receiving end, wherein the encoded JSON data includes the encoding tag and the feature list;
[0017] The receiving end is used to perform the following operations: after receiving the encoded JSON data, call the decoding interface, decode the encoded JSON data through the built-in decoding method of the decoding interface, obtain the original JSON data from the encoded JSON data according to the encoding tag and feature list, and send the decoded original JSON data to the relevant service interface.
[0018] Preferably, encoding is performed by extracting features and removing duplicates from JSON data, including two encoding methods, namely a first encoding method and a second encoding method;
[0019] The first encoding method includes the following steps: extracting a JSON key string from the original JSON data, and de-duplicating the extracted JSON key string into a JSON array, converting the subscript of the array where the JSON key string is located from a numeric format to a string format, and replacing the original key string with the subscript in the string format, obtaining a feature list, and adding encoding annotations to generate an encoded string, and sending the encoded string and the JSON data as encoded JSON data to a receiving end;
[0020] The second encoding method includes the following steps: for the original JSON data, extract the JSON key string and value string, and deduplicate the extracted JSON key string and value string and arrange them into a JSON array, convert the subscript of the array where the JSON key string and value string are located from a numeric format to a string format, and replace the original key string with the subscript in the string format to obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
[0021] Preferably, for the first encoding method, the sending end is used to send the JOSN data and the encoded string to the receiving end through the original interface, or to send the JOSN data to the receiving end through the original interface and send the encoded string to the receiving end through a separate interface;
[0022] For the second encoding method, the encoded JOSN data and the encoded string are sent to the receiving end through the original interface, or the encoded JOSN data is sent to the server through the original interface and the encoded string is sent to the receiving end through a separate interface.
[0023] Preferably, for the first encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the receiving end is used to replace the key string in the encoded JSON data with the string in the feature list to generate the original JSON data;
[0024] For the second encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the receiving end is used to replace the key string and the value string in the encoded JSON data with the string in the feature list to generate the original JSON data.
[0025] The JSON-based interface data encoding method and system of the present invention have the following advantages: JSON data is encoded at the sending end and decoded at the receiving end. The interface call transmits the encoded data, and the amount of the encoded data is much smaller than the original data, which can reduce the pressure of transmission, reduce the risk of network congestion, and improve the throughput of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0027] The present invention is further described below in conjunction with the accompanying drawings.
[0028] Figure 1 This is a flowchart of a JSON-based interface data encoding method according to Example 1;
[0029] Figure 2 This is a schematic diagram of the original JSON in a JSON-based interface data encoding method in Example 1;
[0030] Figure 3 The string generated by encoding using the JSON key extraction and de-duplication arrangement method in a JSON-based interface data encoding method in Example 1;
[0031] Figure 4This is a schematic diagram of returning a JSON key feature string list using a separate interface in a JSON-based interface data encoding method in Example 1;
[0032] Figure 5 This is a schematic diagram of JSON data after encoding according to an interface separation method in a JSON-based interface data encoding method in Example 1. DETAILED DESCRIPTION
[0033] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
[0034] The embodiment of the present invention provides a JSON-based interface data coding method and system for solving the technical problem of network burden when transmitting data in a large amount of JSON interactive data or a resource interface with a very high request frequency.
[0035] Embodiment 1:
[0036] The present invention provides a JSON-based interface data encoding method, which is applied to a sending end and a receiving end, and comprises the following steps:
[0037] Step S100: The client as the sending end requests the original JSON data, calls the encoding interface, encodes the original JSON data by the encoding method built into the encoding interface, encodes the JSON data by extracting features and de-duplicating the JSON data, obtains the encoded JSON data, and sends the encoded JSON data to the server as the receiving end, wherein the encoded JSON data includes an encoding tag and a feature list;
[0038] Step S200: After receiving the encoded JSON data, the server calls the decoding interface, decodes the encoded JSON data through the decoding method built into the decoding interface, obtains the original JSON data from the encoded JSON data according to the encoding tag and feature list, and sends the decoded original JSON data to the relevant service interface.
[0039] In this embodiment, the JSON data is encoded by extracting features and removing duplicates, including two encoding methods, namely a first encoding method and a second encoding method.
[0040] The first encoding method includes the following steps: for the original JSON data, extract the JSON key string, and deduplicate the extracted JSON key string and arrange it into a JSON array, convert the subscript of the array where the JSON key string is located from a numeric format to a string format, and replace the original key string with the subscript in the string format, obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and JSON data as encoded JSON data to the receiving end.
[0041] The first encoding method of this embodiment is to extract only the JSON key string, deduplicate it and arrange it into a JSON array. When encoding, the subscript (number to string) of the array where the feature string is located is used to replace the original key string, add the encoding mark, and generate the encoded string.
[0042] Table 1: Example of the first encoding method:
[0043]
[0044]
[0045] The second encoding method includes the following steps: for the original JSON data, extract the JSON key string and value string, and deduplicate the extracted JSON key string and value string and arrange them into a JSON array, convert the subscript of the array where the JSON key string and value string are located from a numeric format to a string format, and replace the original key string with the subscript in the string format to obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
[0046] The second encoding method of this embodiment is to extract JSON key and value strings (ignore empty strings and other types of data), deduplicate them and arrange them into a JSON array. When encoding, the subscript of the array where the feature string is located (number to string) is used to replace the original key and value strings, add encoding tags, and generate encoded strings.
[0047] Table 2: Example of the second encoding method
[0048]
[0049] For the first encoding method, the JOSN data and the encoded string are sent to the server through the original interface, or the JOSN data is sent to the server through the original interface and the encoded string is sent to the server through a separate interface; for the second encoding method, the encoded JOSN data and the encoded string are sent to the server through the original interface, or the encoded JOSN data is sent to the server through the original interface and the encoded string is sent to the server through a separate interface.
[0050] For the first encoding method, when the original JSON data is obtained from the encoded JSON data according to the encoding tag and the feature list, the key string in the encoded JSON data is replaced with the string in the feature list to generate the original JSON data; for the second encoding method, when the original JSON data is obtained from the encoded JSON data according to the encoding tag and the feature list, the key string and value string in the encoded JSON data are replaced with the string in the feature list to generate the original JSON data.
[0051] In this embodiment, for the first encoding method, the format of the original JSON data is as follows: Figure 2 As shown, after encoding Figure 3 As shown, the length of the original JSON data is 2098 characters. The JSON key extraction and de-duplication arrangement method is used to encode, and the length of the generated JSON is 1699 characters, which is 399 characters less than the original string, and the compression rate is about 81%.
[0052] Note: Compression ratio = (length of string after compression) / (length of string before compression)*100%.
[0053] like Figure 4 As shown, the JSON key feature string list is returned using a separate interface and cached on the request side (only one call is required). Subsequent decoding of data only requires querying the corresponding feature string list locally.
[0054] like Figure 5 As shown in the figure, if the interface separation method is used and the request only returns the result encoded JSON data, the compression rate is about 71%.
[0055] This application proposes a JSON-based interface data encoding and decoding method, that is, when the front-end and back-end interfaces are called, JSON data feature extraction and de-duplication arrangement are performed, that is, the original JSON data is compressed to reduce the amount of data for interface interaction, reduce the amount of data transmitted over the network, save network traffic, and effectively improve system throughput, reduce the risk of network congestion, and improve user experience. It is also possible to perform decoding operations on encoded data, that is, to restore the encoded data to the original JSON data. It is compatible with existing interfaces and interactive data, and the encoding and decoding method is called at the JSON data sending and receiving ends, and the encoding and decoding operations are automatically performed according to the data format to generate the expected JSON data.
[0056] Embodiment 2:
[0057] The present invention discloses a JSON-based interface data encoding system, comprising a sending end and a receiving end.
[0058] The sending end is used to perform the following operations: request the original JSON data, call the encoding interface, encode the original JSON data through the encoding method built into the encoding interface, encode the JSON data by extracting features and de-duplicating the JSON data, obtain the encoded JSON data, and send the encoded JSON data to the receiving end, where the encoded JSON data includes encoding tags and feature lists.
[0059] In this embodiment, the JSON data is encoded by extracting features and removing duplicates, including two encoding methods, namely a first encoding method and a second encoding method.
[0060] The first encoding method includes the following steps: for the original JSON data, extract the JSON key string, and deduplicate the extracted JSON key string and arrange it into a JSON array, convert the subscript of the array where the JSON key string is located from a numeric format to a string format, and replace the original key string with the subscript in the string format, obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and JSON data as encoded JSON data to the receiving end.
[0061] The second encoding method includes the following steps: for the original JSON data, extract the JSON key string and value string, and deduplicate the extracted JSON key string and value string and arrange them into a JSON array, convert the subscript of the array where the JSON key string and value string are located from a numeric format to a string format, and replace the original key string with the subscript in the string format to obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
[0062] For the first encoding method, the sender is used to send the JOSN data and the encoded string to the receiving end through the original interface, or send the JOSN data to the receiving end through the original interface and send the encoded string to the receiving end through a separate interface; for the second encoding method, the encoded JOSN data and the encoded string are sent to the receiving end through the original interface, or send the encoded JOSN data to the server through the original interface and send the encoded string to the receiving end through a separate interface.
[0063] The receiving end is used to perform the following operations: after receiving the encoded JSON data, call the decoding interface, decode the encoded JSON data through the built-in decoding method of the decoding interface, obtain the original JSON data from the encoded JSON data according to the encoding tag and feature list, and send the decoded original JSON data to the relevant service interface.
[0064] In this embodiment, for the first encoding method, when the original JSON data is obtained from the encoded JSON data according to the encoding tag and the feature list, the receiving end is used to replace the key string in the encoded JSON data with the string in the feature list to generate the original JSON data; for the second encoding method, when the original JSON data is obtained from the encoded JSON data according to the encoding tag and the feature list, the receiving end is used to replace the key string and value string in the encoded JSON data with the string in the feature list to generate the original JSON data.
[0065] The system of this embodiment can execute the method disclosed in Example 1 to implement interface data encoding and reduce network burden.
[0066] The present invention has been shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the means in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.
Claims
1. A JSON-based interface data encoding method, characterized in that: Applied to the transmitting end and the receiving end, the method comprises the following steps: The client as the sending end requests the original JSON data, calls the encoding interface, encodes the original JSON data through the encoding method built into the encoding interface, encodes the JSON data by extracting features and de-repeating the JSON data, obtains the encoded JSON data, and sends the encoded JSON data to the server as the receiving end, wherein the encoded JSON data includes the encoding tag and the feature list; After receiving the encoded JSON data, the server calls the decoding interface and decodes the encoded JSON data through the built-in decoding method of the decoding interface. According to the encoding tag and feature list, the original JSON data is obtained from the encoded JSON data, and the decoded original JSON data is sent to the relevant service interface.
2. The JSON-based interface data encoding method according to claim 1, characterized in that: Encoding is performed by extracting features and removing duplicates from JSON data, including two encoding methods, namely a first encoding method and a second encoding method; The first encoding method includes the following steps: extracting a JSON key string from the original JSON data, and de-duplicating the extracted JSON key string into a JSON array, converting the subscript of the array where the JSON key string is located from a numeric format to a string format, and replacing the original key string with the subscript in the string format, obtaining a feature list, and adding encoding annotations to generate an encoded string, and sending the encoded string and the JSON data as encoded JSON data to a receiving end; The second encoding method includes the following steps: for the original JSON data, extract the JSON key string and value string, and deduplicate the extracted JSON key string and value string and arrange them into a JSON array, convert the subscript of the array where the JSON key string and value string are located from a numeric format to a string format, and replace the original key string with the subscript in the string format to obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
3. The JSON-based interface data encoding method according to claim 2, characterized in that: For the first encoding method, the JOSN data and the encoded string are sent to the server through the original interface, or the JOSN data is sent to the server through the original interface and the encoded string is sent to the server through a separate interface; For the second encoding method, the encoded JOSN data and the encoded string are sent to the server through the original interface, or the encoded JOSN data is sent to the server through the original interface and the encoded string is sent to the server through a separate interface.
4. The JSON-based interface data encoding method according to claim 2 or 3, characterized in that: For the first encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the key string in the encoded JSON data is replaced with the string in the feature list to generate the original JSON data; For the second encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the key string and the value string in the encoded JSON data are replaced with the strings in the feature list to generate the original JSON data.
5. A JSON-based interface data encoding system, characterized in that: Used to encode interface data by a JSON-based interface data encoding method as described in any one of claims 1 to 4, the system comprising a sending end and a receiving end; The sending end is used to perform the following operations: request the original JSON data, call the encoding interface, encode the original JSON data through the encoding method built into the encoding interface, encode the JSON data by extracting features and de-repeating the JSON data, obtain the encoded JSON data, and send the encoded JSON data to the receiving end, wherein the encoded JSON data includes the encoding tag and the feature list; The receiving end is used to perform the following operations: after receiving the encoded JSON data, call the decoding interface, decode the encoded JSON data through the built-in decoding method of the decoding interface, obtain the original JSON data from the encoded JSON data according to the encoding tag and feature list, and send the decoded original JSON data to the relevant service interface.
6. The JSON-based interface data encoding system according to claim 5, characterized in that: Encoding is performed by extracting features and removing duplicates from JSON data, including two encoding methods, namely a first encoding method and a second encoding method; The first encoding method includes the following steps: extracting a JSON key string from the original JSON data, and de-duplicating the extracted JSON key string into a JSON array, converting the subscript of the array where the JSON key string is located from a numeric format to a string format, and replacing the original key string with the subscript in the string format, obtaining a feature list, and adding encoding annotations to generate an encoded string, and sending the encoded string and the JSON data as encoded JSON data to a receiving end; The second encoding method includes the following steps: for the original JSON data, extract the JSON key string and value string, and deduplicate the extracted JSON key string and value string and arrange them into a JSON array, convert the subscript of the array where the JSON key string and value string are located from a numeric format to a string format, and replace the original key string with the subscript in the string format to obtain a feature list, and add encoding annotations to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
7. The JSON-based interface data encoding system according to claim 6, characterized in that: For the first encoding method, the sending end is used to send the JOSN data and the encoded string to the receiving end through the original interface, or to send the JOSN data to the receiving end through the original interface and send the encoded string to the receiving end through a separate interface; For the second encoding method, the encoded JOSN data and the encoded string are sent to the receiving end through the original interface, or the encoded JOSN data is sent to the server through the original interface and the encoded string is sent to the receiving end through a separate interface.
8. The JSON-based interface data encoding system according to claim 6 or 7, characterized in that: For the first encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the receiving end is used to replace the key string in the encoded JSON data with the string in the feature list to generate the original JSON data; For the second encoding method, when obtaining the original JSON data from the encoded JSON data according to the encoding tag and the feature list, the receiving end is used to replace the key string and the value string in the encoded JSON data with the string in the feature list to generate the original JSON data.
Citation Information
Patent Citations
Coding method, decoding method, coding system and decoding system
CN103595415A
Data encoding method and device, data decoding method and device, equipment and storage medium
CN110932822A
Encoding and encryption method based on cyberspace knowledge data
CN114519194A
Json data compression method and device based on self-training dictionary coding
CN115941808A
Section-based coding unified conversion method and system
CN116048530A