Data result conversion method and device

By analyzing the response data returned by the API request as a Python object and performing deep copy and replacement conversion, the problem of inconsistent data formats of different API requests is solved, and unified format conversion and efficient processing of data is realized.

CN119848110APending Publication Date: 2025-04-18SHANGHAI ZHUYUN INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311338752.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-16
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

In the existing data visualization platform and business system, the data results obtained by API requests are inconsistent, and data cannot be parsed through common methods, resulting in inefficient data processing.

Method used

By parsing the response data returned by the API request to be object data in Python, deep copy of the data, receiving a replacement dictionary for sorting and substitution conversion, and finally converting the data into a unified format.

Benefits of technology

It realizes the conversion of data obtained from API requests from different sources into a unified format, simplifies the data processing process, improves development efficiency, and supports cross-domain requests and data authorization release.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119848110A_ABST
    Figure CN119848110A_ABST
Patent Text Reader

Abstract

The invention provides a data result conversion method and device. The method comprises the following steps: S1, checking and processing a URL (Uniform Resource Locator) link and a request method of an API (Application Program Interface) request, and sending an HTTP (Hyper Text Transport Protocol) request; s2, analyzing response data returned by the HTTP request into object data in the Python; s3, taking the object data as original data, and performing deep copying on the original data to obtain a data copy; s4, receiving a specified replacement dictionary, sorting the replacement dictionary through a key path length, and performing replacement conversion on the data copy from the deepest level to obtain replacement data; and S5, authorizing and publishing the replacement data. The method is used for converting data obtained by API requests of different sources into a unified data format, so that a developer can conveniently process modules in a unified manner when processing the data, and the development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, and in particular to a method and device for converting data results. Background Art

[0002] In today's digital age, every organization is generating a large amount of data every moment. As the amount of enterprise data continues to increase, business development is also becoming faster and faster, and organizational decisions are becoming more and more dependent on data. Therefore, there are higher requirements for rapid verification and analysis of decisions. Only decisions based on data can ensure scientificity and reduce risks.

[0003] The data sources of existing data visualization platforms and business systems are not single. Most of the data is obtained through API requests. The data result formats of APIs from different sources are also inconsistent, and the data cannot be parsed through a common method.

[0004] In view of this, the present invention is proposed. Summary of the invention

[0005] In view of this, the present invention discloses a data result conversion method and device, which are used to convert data obtained from API requests from different sources into a unified data format, so as to facilitate developers to unify processing modules when processing data and improve development efficiency.

[0006] Specifically, the present invention is achieved through the following technical solutions:

[0007] In a first aspect, the present invention discloses a method for converting data results, which specifically comprises the following steps:

[0008] S1. Check and process the URL link and request method of the API request and send an HTTP request;

[0009] S2. Parsing the response data returned by the HTTP request into object data in Python;

[0010] S3, taking the object data as original data, and performing a deep copy of the original data to obtain a data copy;

[0011] S4, receiving a specified replacement dictionary, sorting the replacement dictionary by key path length, performing replacement transformation on the data copy from the deepest level to obtain replacement data;

[0012] S5. Authorize and publish the replacement data.

[0013] By parsing the response data into object data in Python, a unified data format can be achieved;

[0014] By making a deep copy of the object data, it is possible to avoid contaminating the original data;

[0015] By starting the replacement from the deepest level, you can avoid the situation where the parent object is changed and the child object of the original parent object cannot be found.

[0016] Furthermore, in the step S4, the replacement conversion method includes:

[0017] Determine the path of the corresponding key in the object data using the jsonpath library;

[0018] According to the path of the corresponding key and the type of the object data, the corresponding execution mode is dynamically selected using Python's exec() function to perform the replacement operation.

[0019] Furthermore, the method for performing the replacement operation includes:

[0020] If the type of the object data is a dictionary, the dictionary is replaced with a key-value pair;

[0021] If the type of the object data is a list of dictionaries, then each dictionary in the list is replaced;

[0022] If the object data is nested data, a recursive algorithm is used to traverse and replace.

[0023] By recursively calling itself, it handles the case where the object being changed is a nested dictionary or a nested dictionary. This ensures that the replacement operation can be completed normally when encountering a deeply nested data structure.

[0024] Furthermore, in the step S5, the authorization and publishing method includes:

[0025] The replaced data is displayed, and a new link is generated according to the publishing function of the system, and the third party requests to obtain the data response instantly through the new link.

[0026] Furthermore, the new link requests data between different domains, making a cross-domain request.

[0027] In a second aspect, the present invention discloses a data result conversion device, comprising:

[0028] API request module: checks and processes the URL link and request method of the API request and sends the HTTP request;

[0029] Object data generation module: parses the response data returned by the HTTP request into object data in Python;

[0030] Data copy generation module: taking the object data as original data and performing a deep copy of the original data to obtain a data copy;

[0031] Data replacement module: receiving a specified replacement dictionary, sorting the replacement dictionary by key path length, performing replacement transformation on the data copy from the deepest level to obtain replacement data;

[0032] Data authorization and distribution module: authorizes and publishes the replacement data.

[0033] In a third aspect, the present invention discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the data result conversion method as described in the first aspect.

[0034] In a fourth aspect, the present invention discloses a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the data result conversion method as described in the first aspect are implemented.

[0035] Compared with the prior art, the present invention has the following beneficial effects:

[0036] First, the data result conversion method of the present invention supports a variety of request modes, including custom filling of request parameters, selection of fields to be converted, viewing of original requests and display of converted results. By adjusting and displaying data results, the amount of code can be reduced during development, thus improving development efficiency for front-end and back-end developers.

[0037] Second, the data result conversion method of the present invention can detect the availability of API requests, view the return results of the requests, and has universality;

[0038] Third, the API used for outputting the conversion results of the present invention can be directly used by developers as a general method, thereby improving development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0040] Figure 1 A schematic diagram of a data result conversion method provided by an embodiment of the present invention;

[0041] Figure 2 A schematic diagram of a login interface provided by an embodiment of the present invention;

[0042] Figure 3 A schematic diagram of a system interface provided by an embodiment of the present invention;

[0043] Figure 4 A schematic diagram of a GET request provided in an embodiment of the present invention;

[0044] Figure 5 A schematic diagram of a POST request provided in an embodiment of the present invention;

[0045] Figure 6 A schematic diagram of a selection field provided by an embodiment of the present invention;

[0046] Figure 7 A schematic diagram of filling in corresponding fields provided in an embodiment of the present invention;

[0047] Figure 8 A schematic diagram showing the original request result provided by an embodiment of the present invention;

[0048] Fig. 9 A schematic diagram of replacement data of a request result after converting fields provided by an embodiment of the present invention;

[0049] Fig.10 A schematic diagram of a viewing request interface provided by an embodiment of the present invention;

[0050] Fig.11 A schematic diagram of an interface for viewing request content provided by an embodiment of the present invention;

[0051] Fig.12 A schematic diagram of a publishing function interface provided by an embodiment of the present invention;

[0052] Fig.13 A schematic diagram of a publishing function content display interface provided by an embodiment of the present invention;

[0053] Fig.14 A schematic diagram of a structure for viewing a publishing link provided by an embodiment of the present invention;

[0054] Fig.15 A schematic diagram of a published record provided by an embodiment of the present invention;

[0055] Fig.16 A schematic diagram of a cancel publishing interface provided by an embodiment of the present invention;

[0056] Fig.17 A schematic diagram of a delete record button provided in an embodiment of the present invention;

[0057] Fig.18 A schematic diagram of a modification interface provided by an embodiment of the present invention;

[0058] Fig.19 A schematic diagram of a data result conversion device provided by an embodiment of the present invention;

[0059] Fig. 20 A schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0060] The technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings and specific embodiments, but those skilled in the art will understand that the embodiments described below are part of the embodiments of the present invention, rather than all of the embodiments, and are only used to illustrate the present invention, and should not be regarded as limiting the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0061] In order to more clearly explain the technical solution of the present invention, it is described in the form of specific embodiments below.

[0062] Example

[0063] Reference Figure 1-20 As shown, the present invention discloses a method and device for converting data results, wherein, referring to Figure 1 As shown, the data result conversion method includes the following steps:

[0064] S1. Check and process the URL link and request method of the API request and send an HTTP request;

[0065] S2. Parsing the response data returned by the HTTP request into object data in Python;

[0066] S3, taking the object data as original data, and performing a deep copy of the original data to obtain a data copy;

[0067] S4, receiving a specified replacement dictionary, sorting the replacement dictionary by key path length, performing replacement transformation on the data copy from the deepest level to obtain replacement data;

[0068] S5. Authorize and publish the replacement data.

[0069] The embodiment of the present invention is specifically implemented through the following steps:

[0070] Generate a new return value by operating the fields in the return value of the original request through custom corresponding fields, and the data structure does not change.

[0071] Specific request conversion methods include:

[0072] Check and process the URL link and request method of the API request, and send the HTTP request; receive the response data of the HTTP request, and parse the response data returned by the HTTP request into object data in Python.

[0073] The object data is used as the original data, a deep copy is made to the original data, a data copy is obtained, and the data copy is replaced. This setting can avoid contaminating the original data.

[0074] The incoming replacement dictionary is sorted by path length, and the data copy is replaced and transformed starting from the deepest level. Specifically, replacing from the deepest level can avoid the situation where the parent set object is changed but the child set object of the original parent set object cannot be found.

[0075] Use the jsonpath library to obtain the array of paths where the key of the corresponding object is located, and determine the path of the corresponding key in the object data;

[0076] According to the path of the corresponding key and the type of the object data, the Python exec() function is used to dynamically perform the replacement operation. Specifically, the type of the object data is determined. If the object data type is a dictionary, it is replaced with the key value; if the object data is a list containing dictionaries, each dictionary in the list is replaced. When processing nested data structures, if the dictionary or list is nested, recursive calls are used to handle the situation where the object being changed is a dictionary or nested dictionary; when the object data is a nested dictionary, recursive calls are also used to process the data. This setting ensures that the replacement operation can be completed normally when encountering a deeply nested data structure.

[0077] After the data conversion is completed, the conversion results can be viewed in the system, and the link of the replaced data can be published to third parties for use. Specifically, in this process, the third party needs to be authorized, and the system's publishing function generates a new link. The new link can request data between different domains. This new link can avoid waiting for the system when requested by a third party and can request across domains.

[0078] The operation steps for implementing the embodiment of the present invention are as follows:

[0079] Replace-deploy is a win / mac desktop executable file written in Go language. It is an important tool for one-click deployment of the request result conversion system.

[0080] In this embodiment, the request conversion system is quickly deployed on the DataFlux Func platform through replace-deploy, so that the system can realize the business logic conversion function.

[0081] In the process of data conversion, Figure 2 , user logs in user information and enters the system page.

[0082] After the user logs in to the data conversion system, Figure 3 First, you will see the conversion history on the left and the request module in the middle. The request module is divided into three parts: original request, conversion field, and return result. The original request supports GET and POST methods. The GET request can concatenate parameters after the URL, such as Figure 4 , while the POST request places the parameters in the BODY, such as Figure 5 Through this module, users can send requests to check their validity and view the returned results.

[0083] Specifically, if there is no parameter passing involved, there is no difference in the filling method between the GET method and the POST method. If there is a parameter passing involved, when filling in the parameter, the GET request will concatenate the parameter with "?" after the URL, for example: http: / / rap2api.taobao.org / app / mock / 175972 / testapi?param0=0¶m1=1.

[0084] In the Convert Fields module, users can select the fields to be converted and assign new names to them. The system supports such operations on multiple fields.

[0085] For details, see Figure 6 As shown, after filling in the original ball or clicking the send request of the original request, click "Add one" in the conversion field module, and focus the mouse on the input box of "Click to select parameters", and all the fields in the request result will be displayed.

[0086] See also Figure 7 , select the field you want to convert, and fill in the custom new field name in the "New parameter name" input box. If you need to convert multiple fields, repeat the above steps.

[0087] The returned result shows the original request result and the request result after the fields are converted. Figure 8-9 , where the content displayed by the original request result is the data returned by the original request, that is, the original data; the request result after converting the field is the data obtained by converting the field, that is, the replacement data.

[0088] In addition, users can view detailed local request data or publish the request for use by third-party platforms. The published request link has login-free and cross-domain functions.

[0089] See also Figure 10-11, click View Request to view the details of the local request. The pop-up box will display the request URL, request method, and parameters in the system (will be displayed when using POST method).

[0090] The address for viewing the results is the request viewed within the system. If the link is shared with a third-party platform, a publishing request is required. The new link after publishing realizes the functions of free login and cross-domain request.

[0091] See also Figure 12-18 The operations of the publishing function include publishing, viewing publishing links, and canceling publishing. When performing specific operations, after the conversion field operation is completed, a publishing button will appear in the upper right corner; click the publishing button in the upper right corner, and after success, the viewing publishing link and cancel publishing buttons will appear; share the publishing link externally, and you can get the conversion results without logging into the system.

[0092] The published records will be shown in the history chart on the left for subsequent operations. When displaying them specifically, you can highlight the parts for reminder.

[0093] After publishing the function, a cancel publishing button will appear. Click it to cancel the publishing status. After re-publishing, the previous publishing connection will be reset.

[0094] Click the OK button of the conversion field. After the conversion is successful, the converted record will be automatically added to the history. When the mouse hovers over the record, a delete button will appear on the right. Click the delete button to delete the corresponding history.

[0095] Click on the history record to display the recorded content in the request module. You can modify the content and the corresponding data results will also change.

[0096] In addition, the present invention also provides a data result conversion device, such as Fig.19 As shown, specifically including:

[0097] API request module: checks and processes the URL link and request method of the API request and sends the HTTP request;

[0098] Object data generation module: parses the response data returned by the HTTP request into object data in Python;

[0099] Data copy generation module: taking the object data as original data and performing a deep copy of the original data to obtain a data copy;

[0100] Data replacement module: receiving a specified replacement dictionary, sorting the replacement dictionary by key path length, performing replacement transformation on the data copy from the deepest level to obtain replacement data;

[0101] Data authorization and distribution module: authorizes and publishes the replacement data.

[0102] The system is mainly composed of the above five modules. Through the construction of this system, the purpose of parallel operation can be achieved by mounting the same file system at the same time.

[0103] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above units can refer to the previous method embodiments, which will not be repeated here.

[0104] Fig. 20 This is a schematic diagram of the structure of a computer device disclosed in the present invention. Fig. 20 As shown, the computer device 400 includes at least a memory 402 and a processor 401; the memory 402 is connected to the processor via a communication bus 403, and is used to store computer instructions executable by the processor 401, and the processor 301 is used to read computer instructions from the memory 402 to implement the steps of the data result conversion method described in the above embodiment.

[0105] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for converting data results, characterized in that: The steps include: S1. Check and process the URL link and request method of the API request and send an HTTP request; S2. Parsing the response data returned by the HTTP request into object data in Python; S3, taking the object data as original data, and performing a deep copy of the original data to obtain a data copy; S4, receiving a specified replacement dictionary, sorting the replacement dictionary by key path length, performing replacement transformation on the data copy from the deepest level to obtain replacement data; S5. Authorize and publish the replacement data.

2. The method for converting data results according to claim 1, characterized in that: In the step S4, the replacement conversion method comprises: Determine the path of the corresponding key in the object data using the jsonpath library; According to the path of the corresponding key and the type of the object data, the corresponding execution mode is dynamically selected using Python's exec() function to perform the replacement operation.

3. The method for converting data results according to claim 2, characterized in that: The method for performing the replacement operation comprises: If the type of the object data is a dictionary, the dictionary is replaced with a key-value pair; If the type of the object data is a list of dictionaries, then each dictionary in the list is replaced; If the object data is nested data, a recursive algorithm is used to traverse and replace.

4. The method for converting data results according to claim 1, characterized in that: In the step S5, the authorization and publishing method includes: The replaced data is displayed, and a new link is generated according to the publishing function of the system, and the third party requests to obtain the data response instantly through the new link.

5. The method for converting data results according to claim 4, characterized in that: The new link requests data between different domains, making a cross-domain request.

6. A data result conversion device, using the conversion method according to any one of claims 1 to 5, characterized in that: include: API request module: checks and processes the URL link and request method of the API request and sends the HTTP request; Object data generation module: parses the response data returned by the HTTP request into object data in Python; Data copy generation module: taking the object data as original data and performing a deep copy of the original data to obtain a data copy; Data replacement module: receiving a specified replacement dictionary, sorting the replacement dictionary by key path length, performing replacement transformation on the data copy from the deepest level to obtain replacement data; Data authorization and distribution module: authorizes and publishes the replacement data.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed, the steps of the method for converting the data results described in any one of claims 1 to 5 are implemented.

8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the data result conversion method according to any one of claims 1 to 5 are implemented.