Json-based interface data encoding method and system
By performing feature extraction, deduplication, and encoding on the JSON data at the sending end, and decoding it at the receiving end, the network burden problem of large-volume JSON interaction data or high-frequency request interfaces is solved, achieving more efficient data transmission and system throughput.
Patent Information
- Application Number
- CN202411490027.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2044-10-24
AI Technical Summary
When transmitting large amounts of JSON data or frequently requested resource interfaces, the network load is heavy, which may lead to network congestion and affect the normal use of services.
The JSON data is feature-extracted, deduplicated, and encoded at the sending end, and then decoded at the receiving end. The original JSON data is recovered using the encoding tags and feature list, reducing the amount of data transmitted.
Reduce network transmission pressure, decrease network congestion risk, improve system throughput, and enhance user experience.
Smart Images

Figure CN119484170B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data interaction technology, specifically to a JSON-based interface data encoding method and system. Background Technology
[0002] The separation of front-end and back-end has become a trend in web service development. Applications that use RESTful API interfaces and uniform JSON data returns are widely deployed and used. This means that the front-end and back-end interact with a large amount of JSON data. MQTT publish and subscribe messages also use a large amount of JSON data for interaction. For large amounts of JSON interaction data or resource interfaces with extremely high request frequency, it will put a certain burden on the network access, which may cause network congestion and affect the normal use of services.
[0003] The network burden when transmitting large amounts of JSON data or frequently requested resource interfaces is a technical problem that needs to be solved. Summary of the Invention
[0004] The technical objective of this invention is to address the above-mentioned shortcomings by providing a JSON-based interface data encoding method and system to solve the technical problem of network burden when transmitting 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 and receiving method, applied to both the sending and receiving ends, the method comprising the following steps:
[0006] As the sending client, it requests the original JSON data, calls the encoding interface, encodes the original JSON data using the encoding method built into the encoding interface, encodes the JSON data by extracting features and deduplicating and rearranging the JSON data, obtains the encoded JSON data, and sends the encoded JSON data to the receiving server. The encoded JSON data includes encoding tags and a feature list.
[0007] After receiving the encoded JSON data, the server calls the decoding interface and uses the built-in decoding method of the decoding interface to decode the encoded JSON data. Based on the encoding markers and feature list, the server obtains the original JSON data from the encoded JSON data and sends the decoded original JSON data to the relevant service interface.
[0008] As a preferred method, the JSON data is encoded by extracting features and deduplicating and rearranging them, including two encoding methods: the first encoding method and the second encoding method.
[0009] The first encoding method includes the following steps: For the original JSON data, extract the JSON key string, and de-decode and arrange the extracted JSON key string into a JSON array. Convert the subscript of the array containing the JSON key string from the number format to the string format and replace the original key string with the subscript of the string format to obtain the feature list. Add encoding labels to generate the encoded string, and send the encoded string and the JSON data as encoded JSON data to the 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 de-decompose the extracted JSON key string and value string into a JSON array. Convert the subscripts of the array containing the JSON key string and value string from numeric format to string format, and replace the original key string with the subscripts of the string format to obtain a feature list. Add encoding labels to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
[0011] As a preferred option, 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] As a preferred method, when obtaining the original JSON data from the encoded JSON data based on the encoding marker and feature list, the key string in the encoded JSON data is replaced with the string in the feature list to obtain the generated original JSON data.
[0014] For the second encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding markers and feature list, the key strings and value strings in the encoded JSON data are replaced with strings from the feature list to obtain the generated original JSON data.
[0015] In a second aspect, the present invention provides a JSON-based interface data encoding system for encoding interface data using a JSON-based interface data encoding method as described in any of the first aspects, the system comprising 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 using the encoding method built into the encoding interface, encode the JSON data by extracting features and deduplicating and rearranging the JSON data, obtain the encoded JSON data, and send the encoded JSON data to the receiving end. The encoded JSON data includes encoding tags and a feature list.
[0017] The receiving end performs the following operations: after receiving the encoded JSON data, it calls the decoding interface, decodes the encoded JSON data using the built-in decoding method of the decoding interface, obtains the original JSON data from the encoded JSON data according to the encoding marker and feature list, and sends the decoded original JSON data to the relevant service interface.
[0018] As a preferred method, the JSON data is encoded by extracting features and deduplicating and rearranging them, including two encoding methods: the first encoding method and the second encoding method.
[0019] The first encoding method includes the following steps: For the original JSON data, extract the JSON key string, and de-decode and arrange the extracted JSON key string into a JSON array. Convert the subscript of the array containing the JSON key string from the number format to the string format and replace the original key string with the subscript of the string format to obtain the feature list. Add encoding labels to generate the encoded string, and send the encoded string and the JSON data as encoded JSON data to the 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 de-decompose the extracted JSON key string and value string into a JSON array. Convert the subscripts of the array containing the JSON key string and value string from numeric format to string format, and replace the original key string with the subscripts of the string format to obtain a feature list. Add encoding labels 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 JOSN data and the encoded string to the receiving end through the original interface, or send 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] As a preferred embodiment, for the first encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding marker and feature list, the receiving end replaces the key string in the encoded JSON data with the string in the feature list to obtain the generated original JSON data;
[0024] For the second encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding markers and feature list, the receiving end replaces the key strings and value strings in the encoded JSON data with strings from the feature list to obtain the generated 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. Interface calls transmit encoded data, which significantly reduces the amount of data compared to the original data, thus alleviating transmission pressure, reducing network congestion risks, and improving system throughput. Attached Figure Description
[0026] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] The invention will be further described below with reference to the accompanying drawings.
[0028] Figure 1 This is a flowchart of a JSON-based interface data encoding and decoding method according to Example 1;
[0029] Figure 2 This is a schematic diagram of the original JSON in a JSON-based interface data encoding and decoding method according to Example 1;
[0030] Figure 3 Example 1 illustrates a JSON-based interface data encoding method that uses a JSON key extraction and deduplication method to generate a string.
[0031] Figure 4This is a schematic diagram illustrating how a list of JSON key feature strings is returned using a separate interface in a JSON-based interface data encoding and decoding method as described in Example 1.
[0032] Figure 5 This is a schematic diagram of the JSON data encoded by the interface separation method in Example 1, a JSON-based interface data encoding method. Detailed Implementation
[0033] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. 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 can be combined with each other.
[0034] This invention provides a JSON-based interface data encoding and decoding method and system to solve the technical problem of network burden when transmitting large amounts of JSON interactive data or resource interfaces with extremely high request frequencies.
[0035] Example 1:
[0036] This invention provides a JSON-based interface data encoding and receiving method, applicable to both the sending and receiving ends, comprising the following steps:
[0037] Step S100: As the sending end, the client requests the original JSON data, calls the encoding interface, encodes the original JSON data using the encoding method built into the encoding interface, encodes the JSON data by extracting features and deduplicating and rearranging the JSON data, obtains the encoded JSON data, and sends the encoded JSON data to the receiving end, wherein the encoded JSON data includes encoding tags and feature list;
[0038] Step S200: After receiving the encoded JSON data, the server calls the decoding interface and decodes the encoded JSON data using the built-in decoding method of the decoding interface. Based on the encoding markers and feature list, the server obtains the original JSON data from the encoded JSON data 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 deduplicating and rearranging them, including two encoding methods: the first encoding method and the second encoding method.
[0040] The first encoding method includes the following steps: For the original JSON data, extract the JSON key strings, deduplicate the extracted JSON key strings and arrange them into a JSON array, convert the subscripts of the array containing the JSON key strings from numeric format to string format, and replace the original key strings with the subscripts of the string format to obtain a feature list, add encoding labels, generate an encoded string, and send the encoded string and the JSON data as encoded JSON data to the receiving end.
[0041] The first encoding method in this embodiment extracts only the JSON key string, removes duplicates and arranges it into a JSON array. During encoding, the original key string is replaced with the index of the array containing the feature string (number to string conversion), and an encoding mark is added to generate the encoded string.
[0042] Table 1: Examples 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 de-decompose the extracted JSON key string and value string into a JSON array. Convert the subscripts of the array containing the JSON key string and value string from numeric format to string format, and replace the original key string with the subscripts of the string format to obtain a feature list. Add encoding labels 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 in this embodiment extracts the JSON key and value strings (ignoring empty strings and other types of data), removes duplicates and arranges them into a JSON array. During encoding, the original key and value strings are replaced with the index of the array containing the feature string (number to string conversion), and an encoding mark is added to generate the encoded string.
[0047] Table 2: Examples 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 obtaining the original JSON data from the encoded JSON data based on the encoding markers and feature list, the key strings in the encoded JSON data are replaced with strings from the feature list to obtain the generated original JSON data. For the second encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding markers and feature list, the key strings and value strings in the encoded JSON data are replaced with strings from the feature list to obtain the generated 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, it is as follows Figure 3 As shown, the original JSON data is 2098 characters long. Using the JSON key extraction and deduplication method, the generated JSON is 1699 characters long, which is 399 characters shorter than the original string, resulting in a compression rate of approximately 81%.
[0052] Note: Compression ratio = (length of the string after compression) / (length of the string before compression) * 100%.
[0053] like Figure 4 As shown, a list of JSON key feature strings is returned using a separate interface and cached on the request side (only needs to be called once). Subsequent data decoding only requires querying the corresponding feature string list locally.
[0054] like Figure 5 As shown, if the interface separation method is used and the request only returns JSON data in the result encoding, the compression rate is approximately 71%.
[0055] This application proposes a JSON-based interface data encoding and decoding method. During front-end and back-end interface calls, JSON data features are extracted and deduplicated, compressing the original JSON data to reduce the amount of data exchanged and transmitted over the network, saving network bandwidth. This effectively improves system throughput, reduces network congestion risk, and enhances user experience. It can also decode encoded data, restoring it to its original JSON form. It is compatible with existing interfaces and interaction data, automatically performing encoding and decoding operations based on the data format by calling the encoding and decoding method at both the sending and receiving ends of the JSON data, generating the desired JSON data.
[0056] Example 2:
[0057] This invention discloses a JSON-based interface data encoding system, comprising a sender and a receiver.
[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 using the encoding method built into the encoding interface, encode the JSON data by extracting features and deduplicating and rearranging the data, obtain the encoded JSON data, and send the encoded JSON data to the receiving end. The encoded JSON data includes encoding tags and a feature list.
[0059] In this embodiment, JSON data is encoded by feature extraction and deduplication, including two encoding methods: the first encoding method and the second encoding method.
[0060] The first encoding method includes the following steps: For the original JSON data, extract the JSON key strings, deduplicate the extracted JSON key strings and arrange them into a JSON array, convert the subscripts of the array containing the JSON key strings from numeric format to string format, and replace the original key strings with the subscripts of the string format to obtain a feature list, add encoding labels, generate an encoded string, and send the encoded string and the 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 de-decompose the extracted JSON key string and value string into a JSON array. Convert the subscripts of the array containing the JSON key string and value string from numeric format to string format, and replace the original key string with the subscripts of the string format to obtain a feature list. Add encoding labels 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 sending end sends the JOSN data and the encoded string to the receiving end through the raw interface, or sends the JOSN data to the receiving end through the raw interface and sends the encoded string to the receiving end through a separate interface; for the second encoding method, the sending end sends the encoded JOSN data and the encoded string to the receiving end through the raw interface, or sends the encoded JOSN data to the server through the raw interface and sends the encoded string to the receiving end through a separate interface.
[0063] The receiving end performs the following operations: after receiving the encoded JSON data, it calls the decoding interface, decodes the encoded JSON data using the built-in decoding method of the decoding interface, obtains the original JSON data from the encoded JSON data according to the encoding marker and feature list, and sends the decoded original JSON data to the relevant service interface.
[0064] In this embodiment, for the first encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding marker and feature list, the receiving end replaces the key strings in the encoded JSON data with strings from the feature list to obtain the generated original JSON data; for the second encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding marker and feature list, the receiving end replaces the key strings and value strings in the encoded JSON data with strings from the feature list to obtain the generated original JSON data.
[0065] The system in this embodiment can execute the method disclosed in Embodiment 1 to implement interface data encoding, thereby reducing network burden.
[0066] The present invention has been shown and described in detail above with reference to 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 will know that more embodiments of the present invention can be obtained by combining the means in the different embodiments described above, and these embodiments are also within the protection scope of the present invention.
Claims
1. A method for encoding and uncoding interface data based on JSON, characterized in that, Applied to both the sending and receiving ends, the method includes the following steps: As the sending client, it requests the original JSON data, calls the encoding interface, encodes the original JSON data using the encoding method built into the encoding interface, encodes the JSON data by extracting features and deduplicating and rearranging the JSON data, obtains the encoded JSON data, and sends the encoded JSON data to the receiving server. The encoded JSON data includes encoding tags and a feature list. After receiving the encoded JSON data, the server calls the decoding interface and decodes the encoded JSON data using the built-in decoding method of the decoding interface. Based on the encoding markers and feature list, the server obtains the original JSON data from the encoded JSON data and sends the decoded original JSON data to the relevant service interface. The encoding of JSON data involves feature extraction and deduplication, and includes two encoding methods: the first encoding method and the second encoding method. The first encoding method includes the following steps: For the original JSON data, extract the JSON key string, and de-decode and arrange the extracted JSON key string into a JSON array. Convert the subscript of the array containing the JSON key string from the number format to the string format and replace the original key string with the subscript of the string format to obtain the feature list. Add encoding labels to generate the encoded string, and send the encoded string and the JSON data as encoded JSON data to the receiving end. The second encoding method includes the following steps: For the original JSON data, extract the JSON key string and value string, and de-decompose the extracted JSON key string and value string into a JSON array. Convert the subscripts of the array containing the JSON key string and value string from numeric format to string format, and replace the original key string with the subscripts of the string format to obtain a feature list. Add encoding labels to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
2. The JSON-based interface data encoding and decoding method according to claim 1, characterized in that, For the first encoding method, the JOSN data and the encoded string are sent to the server through the raw interface, or the JOSN data is sent to the server through the raw 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.
3. The JSON-based interface data encoding and decoding method according to claim 1 or 2, characterized in that, For the first encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding mark and feature list, the key string in the encoded JSON data is replaced with the string in the feature list to obtain the generated original JSON data; For the second encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding markers and feature list, the key strings and value strings in the encoded JSON data are replaced with strings from the feature list to obtain the generated original JSON data.
4. A JSON-based interface data encoding system, characterized in that, The system is used for encoding interface data using a JSON-based interface data encoding method as described in any one of claims 1-3, and includes 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 using the encoding method built into the encoding interface, encode the JSON data by extracting features and deduplicating and rearranging the JSON data, obtain the encoded JSON data, and send the encoded JSON data to the receiving end. The encoded JSON data includes encoding tags and a feature list. The receiving end is used to perform the following operations: after receiving the encoded JSON data, it 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 mark and feature list, and sends the decoded original JSON data to the relevant service interface; The encoding of JSON data involves feature extraction and deduplication, and includes two encoding methods: the first encoding method and the second encoding method. The first encoding method includes the following steps: For the original JSON data, extract the JSON key string, and de-decode and arrange the extracted JSON key string into a JSON array. Convert the subscript of the array containing the JSON key string from the number format to the string format and replace the original key string with the subscript of the string format to obtain the feature list. Add encoding labels to generate the encoded string, and send the encoded string and the JSON data as encoded JSON data to the receiving end. The second encoding method includes the following steps: For the original JSON data, extract the JSON key string and value string, and de-decompose the extracted JSON key string and value string into a JSON array. Convert the subscripts of the array containing the JSON key string and value string from numeric format to string format, and replace the original key string with the subscripts of the string format to obtain a feature list. Add encoding labels to generate an encoded string, and send the encoded string and the encoded JSON data as encoded JSON data to the receiving end.
5. The JSON-based interface data encoding system according to claim 4, characterized in that, For the first encoding method, the sending end can send JOSN data and the encoded string to the receiving end through the raw interface, or send JOSN data to the receiving end through the raw 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.
6. The JSON-based interface data encoding system according to claim 4 or 5, characterized in that, For the first encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding mark and feature list, the receiving end replaces the key string in the encoded JSON data with the string in the feature list to obtain the generated original JSON data; For the second encoding method, when obtaining the original JSON data from the encoded JSON data based on the encoding markers and feature list, the receiving end replaces the key strings and value strings in the encoded JSON data with strings from the feature list to obtain the generated 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