A data processing method, apparatus and device, and a storage medium

By generating a JSON tree collection and using the parent series table to locate the operation position, the problem of low efficiency in writing JSON interface documents is solved, and the automatic generation and random editing of JSON data are realized, thus improving the efficiency of writing and modifying.

CN115857888BActive Publication Date: 2026-02-24CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111121249.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-24
Publication Date
2026-02-24
Estimated Expiration
2041-09-24

AI Technical Summary

Technical Problem

When using JSON to write API documentation, it is necessary to manually determine the locations to be modified and execute the modifications, which is inefficient and prone to errors.

Method used

By determining the JSON tree set, generating the parent series table of the nodes, and locating the position to be operated based on the parent series table to execute the operation command, the automatic generation and random editing of JSON data are achieved.

Benefits of technology

It improves the efficiency of writing and modifying JSON data, reduces repetitive manual operations, and increases the efficiency of writing test case code for interface automation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115857888B_ABST
    Figure CN115857888B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a data processing method, device and equipment, and a storage medium. The method comprises: determining a JSON tree set; wherein the JSON tree set comprises at least one JSON tree, and each JSON element corresponds to a JSON tree; in the case that there is an unprocessed JSON tree in the JSON tree set, determining a to-be-processed JSON tree from the unprocessed JSON tree; generating a parent list of a node according to the node in the to-be-processed JSON tree; locating to a to-be-operated position according to the parent list, and executing an operation command corresponding to the to-be-operated position. In this way, since the to-be-operated position in the JSON tree set can be located according to the parent list of the node and the corresponding operation command is executed, the automatic generation and random editing of JSON data are realized according to the JSON tree set, and the tedious writing and modification actions do not need to be repeatedly performed manually, thereby improving the writing and modification efficiency of the JSON data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automated testing technology, and in particular to a data processing method, apparatus, device, and storage medium. Background Technology

[0002] JavaScript Object Notation (JSON) is a lightweight data-interchange format that uses a text format completely independent of programming languages ​​to store and represent data. JSON can convert a set of data represented in a JavaScript object into a string, which can then be easily transmitted between networks or programs and restored to the data format supported by various programming languages ​​when needed. Its concise and clear hierarchical structure makes JSON an ideal data exchange language; it is easy for humans to read and write, and also easy for machines to parse and generate.

[0003] However, when using JSON to write API documentation, if the value of a certain node needs to be modified, developers often need to manually determine the location to be modified and execute the corresponding changes, which is inefficient and prone to errors. Summary of the Invention

[0004] This application provides a data processing method, apparatus, device, and storage medium that can improve the efficiency of writing and modifying JSON data.

[0005] The technical solution of this application is implemented as follows:

[0006] In a first aspect, embodiments of this application provide a data processing method, the method comprising:

[0007] Determine a set of JSON trees; wherein the set of JSON trees includes at least one JSON tree, and each JSON element corresponds to one JSON tree;

[0008] If there are unprocessed JSON trees in the JSON tree set, determine the JSON tree to be processed from the unprocessed JSON trees;

[0009] Generate a parent series table for each node based on the nodes in the JSON tree to be processed;

[0010] Locate the position to be operated on based on the parent series table, and execute the operation command corresponding to the position to be operated on.

[0011] Secondly, embodiments of this application provide a data processing apparatus, which includes a determining unit, a generating unit, and an operating unit, wherein...

[0012] The determining unit is configured to determine a set of JSON trees; wherein the set of JSON trees includes at least one JSON tree, and each JSON element corresponds to one JSON tree; and if there are unprocessed JSON trees in the set of JSON trees, to determine a JSON tree to be processed from the unprocessed JSON trees.

[0013] The generation unit is configured to generate a parent series table of the nodes based on the nodes in the JSON tree to be processed;

[0014] The operation unit is configured to locate the position to be operated based on the parent series table and execute the operation command corresponding to the position to be operated.

[0015] Thirdly, embodiments of this application provide an electronic device, which includes a memory and a processor, wherein...

[0016] The memory is used to store computer programs that can run on the processor;

[0017] The processor is configured to execute the data processing method as described in the first aspect when running the computer program.

[0018] Fourthly, embodiments of this application provide a computer storage medium storing a computer program that, when executed by at least one processor, implements the data processing method as described in the first aspect.

[0019] This application provides a data processing method, apparatus, device, and storage medium that determines a JSON tree set, wherein the JSON tree set includes at least one JSON tree, and each JSON element corresponds to one JSON tree. If unprocessed JSON trees exist in the JSON tree set, a JSON tree to be processed is determined from these unprocessed trees. A parent list of the nodes in the JSON tree to be processed is generated. The position to be operated on is located based on the parent list, and the corresponding operation command is executed. Thus, because the position to be operated on in the JSON tree set can be located based on the parent list of the nodes and the corresponding operation command executed, the automatic generation and random editing of JSON data are achieved based on the JSON tree set, eliminating the need for repetitive and tedious manual writing and modification actions, thereby improving the efficiency of writing and modifying JSON data. Attached Figure Description

[0020] Figure 1 A flowchart illustrating a data processing method provided in an embodiment of this application;

[0021] Figure 2A flowchart illustrating another data processing method provided in an embodiment of this application;

[0022] Figure 3 This is a schematic diagram of the composition structure of a data processing device provided in an embodiment of this application;

[0023] Figure 4 This is a schematic diagram of the composition structure of another data processing device provided in an embodiment of this application;

[0024] Figure 5 A schematic diagram of the composition structure of an electronic device provided in an embodiment of this application;

[0025] Figure 6 This is a schematic diagram of the composition structure of another electronic device provided in an embodiment of this application. Detailed Implementation

[0026] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for explaining the relevant application and not for limiting the application. Furthermore, it should be noted that, for ease of description, only the parts related to the relevant application are shown in the accompanying drawings.

[0027] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0028] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0029] It should be noted that the terms "first, second, and third" used in the embodiments of this application are merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, and third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0030] Currently, the interface automation solutions provided by related technologies can address the inconvenience caused by frequent test case modifications due to changes in interface elements by including test data, expected results, and one or more user keywords in the test case design; parsing web pages and generating middleware variables corresponding to page elements to solve the problem; or automatically generating test cases based on user-defined data. However, none of these solutions offer efficient implementations for parameter editing. For example, when locating an element that needs assertion, these solutions still require obtaining JSON data in different hierarchical formats.

[0031] In other words, the traditional process of writing automated API test cases involves building the test cases layer by layer based on the input parameters (using JSON as an example) described in the API documentation. This involves creating either a JSON object (JSONObject) or a JSON array (JSONArray), adding and populating data layer by layer, and filling in header information. However, because the JSON format and components differ for each API, the workload of building or modifying the value of a specific node is often quite large. If the value of any node could be automatically built and modified based on the API documentation, or if the value of any node could be modified using existing JSON string data, then the amount of code required to write automated API test cases would be greatly reduced, and efficiency would be significantly improved.

[0032] Based on this, embodiments of this application provide a data processing method. The basic idea of ​​this method is: to determine a JSON tree set; wherein the JSON tree set includes at least one JSON tree, and each JSON element corresponds to one JSON tree; if there are unprocessed JSON trees in the JSON tree set, to determine the JSON tree to be processed from the unprocessed JSON trees; to generate a parent series table of the nodes in the JSON tree to be processed; to locate the position to be operated on based on the parent series table, and to execute the operation command corresponding to the position to be operated on. In this way, since the position to be operated on in the JSON tree set can be located based on the parent series table of the nodes and the corresponding operation command can be executed, the automatic generation and random editing of JSON data can be realized based on the JSON tree set, and there is no need to manually repeat the tedious writing and modification actions, thereby improving the efficiency of writing and modifying JSON data.

[0033] The embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0034] In one embodiment of this application, see [link to embodiment]. Figure 1 This illustrates a flowchart of a data processing method provided in an embodiment of this application. Figure 1 As shown, the method may include:

[0035] S101. Determine the JSON tree set; wherein the JSON tree set includes at least one JSON tree, and each JSON element corresponds to one JSON tree.

[0036] It should be noted that the data processing method provided in this application embodiment can be applied to a data processing device or an electronic device integrated with such a device. Here, the electronic device may be such as a computer, smartphone, tablet computer, laptop computer, handheld computer, personal digital assistant (PDA), navigation device, server, etc., and this application embodiment does not specifically limit it.

[0037] It should also be noted that the data processing method provided in this application embodiment can be used to convert a JSON tree collection into a JSON file. This JSON file is in JSON format and can be described using JSON strings. It is typically interface documentation information, or it can be any JSON format file such as a log document. The data processing method provided in this application embodiment can also be used to generate a corresponding JSON tree collection based on the JSON file. That is, this application embodiment can at least achieve the mutual conversion between JSON files and JSON tree collections.

[0038] In this embodiment, the JSON tree collection may include at least one JSON tree, and each JSON tree records the element information of a JSON element; that is, each JSON tree corresponds to one JSON element. A JSON element can be element information from a JSON file; for example, for interface documentation information, a JSON element can be a line from that interface documentation information. Here, the JSON tree collection can also be called a JsonTree class collection, or simply listJsonTree; the JSON tree can also be called a JsonTree class, or simply JsonTree.

[0039] Regarding the method for determining the JSON tree set, in some embodiments, determining the JSON tree set may include:

[0040] Obtain the first JSON file; the first JSON file may include at least the API documentation or a JSON string;

[0041] Read the API documentation or iterate through the JSON string to obtain at least one JSON element;

[0042] Generate at least one JSON tree based on at least one JSON element;

[0043] Determine the set of JSON trees based on at least one JSON tree.

[0044] It should be noted that, in this embodiment, the first JSON file can be a document in JSON format. The first JSON file may at least include interface documentation or a JSON string; additionally, it may also include log documents or tables, etc. This embodiment does not specifically limit the source of the first JSON file.

[0045] It should also be noted that after obtaining the first JSON file, the API documentation or JSON string is read to obtain at least one JSON element. For example, when the first JSON file is an API documentation, one line in the API documentation can represent one JSON element.

[0046] It should also be noted that by processing each of the at least one JSON element obtained, at least one JSON tree can be generated corresponding to that JSON element; that is, one JSON tree is generated for each JSON element. Then, after obtaining at least one JSON tree, all the JSON trees are stored in a JSON tree collection, thus obtaining a JSON tree collection composed of JSON trees.

[0047] Furthermore, in some embodiments, generating at least one JSON tree based on at least one JSON element may include:

[0048] Retrieve the element information corresponding to each JSON element in at least one JSON element;

[0049] Based on the element information corresponding to each JSON element, generate a JSON tree corresponding to each JSON element to obtain at least one JSON tree.

[0050] It should be noted that after obtaining at least one JSON element, this embodiment of the application can also obtain the element information corresponding to each JSON element. For each JSON element, its corresponding element information is recorded to form a JSON tree, thus obtaining the JSON tree corresponding to each JSON element.

[0051] Specifically, for at least one JSON element, this embodiment of the application can recursively obtain each different type of JSON element layer by layer and sequentially, and generate a JSON tree after obtaining the element information of each JSON element.

[0052] For each JSON element, in some embodiments, the element information may include at least one of the following: parent node, node, node value, node type, and element index in the JSON array; wherein the node type may include at least one of the following: JSON object, JSON array, or string.

[0053] It should be noted that when determining the JSON tree corresponding to a JSON element, the element information of the JSON element can at least include the parent node, the key node, the value node, and the type node; for JSON elements whose node type is a JSON array, the element information also includes the element index.

[0054] In addition, in practical applications, the element information may include, but is not limited to, the several types of element information listed in the embodiments of this application. Those skilled in the art may add new types of element information in combination with actual needs, or only record some of the element information listed in the embodiments of this application. The embodiments of this application do not make specific limitations in this regard.

[0055] In this way, the element information of each JSON element is recorded to form a JSON tree. Each JSON element corresponds to a JSON tree, and the variables of the JSON tree include the parent node, the value of the node, the type of the node, and may also include the element index of the JSON array.

[0056] The types of nodes can include at least JSON objects (JSONObject), JSON arrays (JSONArray), and strings (String).

[0057] It's important to note that in JSON, a JSONObject is typically enclosed in curly braces {}, and its data structure is usually a key-value pair structure of {key1:value1, key2:value2, ...}. In object-oriented languages, the key is an object's property, and the value is the corresponding value.

[0058] JSONArrays are typically enclosed in square brackets [], and their data structure is usually an indexed structure of ["java", "javascript", "vb", ...]. In JSON, JSON arrays are a special data type; they can also be used with key-value pairs like objects, but indexing is still the most common method.

[0059] The process of converting the first JSON document into a JSON tree collection is completed by storing all the generated JSON trees into a JSON tree collection.

[0060] It should also be noted that for a JSON tree collection, on the one hand, it can be restored to the initial first JSON file; on the other hand, when needed, the node that needs to be processed can be quickly located and the corresponding operation command can be executed. In this way, a new JSON file can be generated based on the JSON tree collection, realizing the automated and rapid writing of JSON files.

[0061] In other words, during the process of generating a JSON file from a JSON tree collection, it is possible to restore the original JSON file without making any modifications; or, after executing the corresponding operation commands on the nodes that need to be executed, a new JSON file is generated, thus eliminating the need to spend a lot of manpower and resources to rewrite JSON files adapted to new scenarios (such as interface documentation information).

[0062] S102. If there are unprocessed JSON trees in the JSON tree set, determine the JSON tree to be processed from the unprocessed JSON trees.

[0063] S103. Generate a parent series table of nodes based on the nodes in the JSON tree to be processed.

[0064] S104. Locate the position to be operated based on the parent series table and execute the operation command corresponding to the position to be operated.

[0065] It should be noted that when generating a JSON file based on the JSON tree set, embodiments of this application can determine the JSON trees to be processed one by one in sequence and process them one by one. Therefore, in some embodiments, after determining the JSON tree set, the method may further include:

[0066] Determine if an unprocessed JSON tree exists in the JSON tree collection;

[0067] If there are unprocessed JSON trees in the JSON tree collection, then proceed with the step of determining the JSON tree to be processed from the unprocessed JSON trees;

[0068] If there is no unprocessed JSON tree in the JSON tree collection, the JSON element corresponding to the position to be operated on is restored, and a second JSON file is generated.

[0069] It's important to note that when processing a collection of JSON trees to generate a second JSON file, the processing can be done sequentially, tree by tree. Therefore, the process first checks if any unprocessed JSON trees exist in the collection. If so, the tree to be processed is identified, and a parent list is generated based on its node. This parent list can include the node's parent element and all subsequent parent elements. This allows for quick location of the node within the JSON tree collection.

[0070] After obtaining the parent list of the nodes, the position to be operated on in the JSON tree collection is located based on the parent list, that is, the value of the node at which position in the JSON tree collection needs to be operated.

[0071] If there are no unprocessed JSON trees in the JSON tree collection, it means that all JSON trees in the JSON tree collection have been processed. At this point, the process can be terminated, and the JSON element corresponding to the position to be operated on can be restored to generate the second JSON file.

[0072] In some embodiments, executing the operation command corresponding to the location to be operated on may include:

[0073] At the location to be operated on, execute the command to create a JSON object, and / or execute the command to create a JSON array, and / or modify the value of a node, and / or delete the value of a node.

[0074] It should be noted that, in the embodiments of this application, the operation command for the position to be operated on may include at least creating a JSON object or a JSON array at the position to be operated on, and / or modifying the value of the node at the position to be operated on, and / or deleting the value of the node at the position to be operated on.

[0075] It should also be noted that when modifying the value of a node at the desired location, if the value of that node is unique within the JSON tree set, then the modification operation can be performed directly according to the preset function; if the value of the node is not unique, then the value of the node can also be quickly modified by combining the index of each JSON tree when creating the JSON tree set (this index can be the sequence number of the JSON tree, etc.).

[0076] Furthermore, the process of recovering a JSON string from a JSON tree collection is essentially the process of adding and / or assigning values ​​to nodes at specific positions. Assigning a null value to a node represents deletion. Thus, even though the JSON tree structure for that node remains intact after being assigned null, the node effectively no longer has a value.

[0077] In other words, in this embodiment, the automatic generation and random editing of JSON data can be achieved according to actual needs. First, interface information can be read from an interface document. If the interface document is a table, then each row in the document table corresponds to a JSON tree, and each JSON tree is an element in a JSON tree set. Then, after the JSON tree set is generated, each element in the JSON tree set is traversed, and a parent series table of the key is generated based on the key in the JSON tree set. Based on the parent series table, the position to be operated is located, and then commands such as create, delete, or modify are executed.

[0078] If you only need to execute commands at one or a few locations within a JSON tree collection, you can locate those locations and then execute commands such as create, delete, or modify. This allows for random editing of the JSON data.

[0079] If modifications are needed to the entire JSON tree collection to generate / restore the interface documentation, the JSON tree collection is traversed. For locations that do not require modification, they are directly restored. For locations that require modification, the corresponding operation commands are executed, and then the next JSON tree is traversed until all JSON trees are restored to JSON elements, resulting in the second JSON file.

[0080] Furthermore, embodiments of this application can also compare the first JSON file and the second JSON file to determine whether any JSON data is lost during the conversion between the JSON file and the JSON tree collection. Therefore, in some embodiments, after generating the second JSON file, the method may further include:

[0081] The first and second JSON files are sorted and compared to determine the comparison result; the JSON tree set is generated based on the first JSON file.

[0082] If the comparison result indicates that the first JSON file and the second JSON file are the same, then it is determined that the JSON tree set information is complete and that there is no missing information in the second JSON file;

[0083] If the comparison result indicates that the first JSON file and the second JSON file are different, then it is determined that the JSON tree set information is incomplete, and / or, it is determined that the second JSON file has missing information.

[0084] It should be noted that, in this embodiment of the application, the first JSON file used to generate the JSON tree set and the second JSON file generated from the JSON tree set can be compared to determine whether the first JSON file and the second JSON file before and after the conversion are the same.

[0085] It should also be noted that when no operations such as adding, deleting, or modifying are performed on each position to be operated on, and only its corresponding JSON element is restored, the resulting second JSON file should be consistent with the original first JSON file. Therefore, in this embodiment, the first JSON file and the second JSON file directly restored from the JSON class collection can be compared to determine their consistency. This also allows for verification of the accuracy and reliability of the conversion.

[0086] Specifically, the second JSON file is sorted and compared to determine the comparison result. If the comparison result indicates that the first JSON file and the second JSON file are the same, it means that after converting the first JSON file into a JSON tree set, the element information in the JSON tree set is complete, that is, the element information of all JSON elements is completely recorded in the JSON tree set; moreover, there is no information loss in the second JSON file, that is, the recovery process from the JSON tree set is normal and complete, and there is no information loss; indicating that the conversion process is accurate and reliable.

[0087] If the first JSON file and the second JSON file are different, it means that during the process of converting the first JSON file into a JSON tree collection, some element information of some JSON elements may not have been completely recorded, and / or, during the process of restoring the second JSON file from the JSON tree collection, there may have been problems that caused some information to be lost. This indicates that there are problems with the accuracy and reliability of the conversion process. In this case, it may be due to problems with program operation or errors in code writing, and the problems need to be modified.

[0088] In this way, by comparing the first JSON file and the second JSON file, it is possible to determine in advance whether the conversion process between the JSON file and the JSON tree collection is reliable and accurate, thus avoiding the generation of erroneous information when using the JSON tree collection to generate a new JSON file.

[0089] This embodiment provides a data processing method by determining a JSON tree set, wherein the JSON tree set includes at least one JSON tree, and each JSON element corresponds to one JSON tree; if there are unprocessed JSON trees in the JSON tree set, a JSON tree to be processed is determined from the unprocessed JSON trees; a parent series table of the nodes in the JSON tree to be processed is generated; the position to be operated on is located according to the parent series table, and the operation command corresponding to the position to be operated on is executed. In this way, since the position to be operated on in the JSON tree set can be located according to the parent series table of the nodes and the corresponding operation command can be executed, the automatic generation and random editing of JSON data are realized, eliminating the need for manual repetition of tedious writing and modification actions, thus improving the efficiency of writing and modifying JSON data. This method provides a simple and efficient way to generate and edit JSON format parameters when writing automated test cases for interfaces.

[0090] In another embodiment of this application, see Figure 2 This illustrates a flowchart of another data processing method provided in an embodiment of this application. Figure 2 As shown, the method may include:

[0091] S201. Read the interface document and store it in a JSON tree collection, or iterate through the JSON string and store it in a JSON tree collection.

[0092] It should be noted that the data processing method provided by the embodiments of this application can conveniently and efficiently convert between interface documents (or JSON strings) and JSON tree collections. Furthermore, the embodiments of this application can generate JSON tree collections not only from interface documents, but also from log documents, etc. That is, any document that can be represented by a JSON string, or a file that can be converted into a JSON string after certain transformations, can be converted into a JSON tree collection using the method provided by the embodiments of this application.

[0093] In the process of generating the JSON tree collection, this embodiment of the application iterates through the JSON string to obtain the element information of each JSON element in the JSON string. Specifically, when iterating through the JSON string, a recursive approach can be used to obtain each element of different types layer by layer in sequence, recording the parent node, node, node value, node type (which may include basic types such as JSON object, JSON array, and string), and the element index of the JSON array for each element.

[0094] In other words, the element information of each JSON element in the JSON string is recorded to obtain a JSON tree for each JSON element. Each JSON tree can contain the parent node, node, node value, node type, and element index of the JSON value. That is, the relevant information of each node in the JSON string is converted into a JSON tree.

[0095] The traversed information is stored in a JSON tree collection. For the API documentation, all JSON elements in the API documentation are converted into JSON trees and then stored in a JSON tree collection, thus completing the process of converting the API documentation into a JSON tree collection.

[0096] S202. Determine if there are any JSON trees to be processed in the JSON tree collection.

[0097] S203. Generate a parent series table of nodes based on the nodes in the JSON tree.

[0098] S204. Based on the parent series table, locate the position to be created / deleted / modified.

[0099] S205. Execute the create / delete / modify command.

[0100] It should be noted that steps S202 to S206 represent the steps of generating interface documents based on the JSON tree collection.

[0101] When a complete interface document needs to be generated from the JSON tree collection, steps S205 to S205 are executed repeatedly until all JSON trees are converted into JSON elements.

[0102] If you only need to modify a specific location or part of the JSON tree, or only need to restore a portion of the API documentation, you can directly locate the location requiring processing and execute the corresponding command. If you need to view the JSON tree at a specific location, you can use traversal to locate the desired position.

[0103] Specifically, during the cyclic execution of steps S202 to S206, it is first determined whether there are any JSON trees to be processed in the JSON tree collection. If there are no more JSON trees to be processed in the JSON tree collection, it means that all JSON trees have been converted or there is no need to perform related operation instructions on the JSON trees, and the restored JSON string can be returned directly.

[0104] That is, for step S202, if the judgment result is yes, then step S203 is executed; otherwise, step S206 is executed.

[0105] It should also be noted that during the process of generating interface documentation from a collection of JSON trees, each JSON tree can be processed sequentially. After identifying a JSON tree to be processed, the parent list of the nodes in the JSON tree is first generated. The parent list of a node represents a list of its parent elements that are recursively pushed upwards from that node. In this way, the position to be operated can be quickly located through the parent list of the nodes.

[0106] After locating the position to be operated on, execute the operation command for that position. This operation command may include creating a JSON object at that position, creating a JSON array at that position, deleting the value of a node at that position (remove), or modifying the value of a key at that position (put).

[0107] For example, when you need to delete the value of a node at a certain position, you can assign the value null to that node to indicate deletion. This way, even if the position is restored, although the structure of the JSON element is preserved, the node's value no longer exists.

[0108] S206. Return the restored JSON string.

[0109] It should be noted that a JSON tree corresponds to a JSON element in a JSON string. Once all the JSON trees in the JSON tree collection have been restored to their corresponding JSON elements, the restored JSON string is obtained. If an API document is generated, then the returned result is the restored API document.

[0110] For a JSON string that is directly restored without any modifications (i.e., no JSON objects and / or JSON arrays were created, and no node values ​​were modified or deleted), the restored JSON string can be compared with the initial string used to generate the JSON tree collection. If the comparison results show that the two are the same, it means that the converted JSON information is complete and there is no loss after restoration.

[0111] Furthermore, for multi-level nested JSON strings consisting of JSON arrays and JSON objects, the method proposed in this application can still be used for verification or modification. That is, for multi-level nested JSON strings, it is still possible to traverse them to generate a JSON tree collection, and then recover the nested JSON strings element by element from the JSON tree collection, comparing the consistency of the JSON strings before and after the conversion.

[0112] In other words, the data processing method provided in this application embodiment can at least achieve the following functions:

[0113] First, it can iterate through and obtain complete information about each JSON element in the JSON string (mainly including the parent node, node, value of the node, type of the node, and element index of the JSON array).

[0114] Secondly, a class (JsonTree) can be used to describe the complete information of a JSON element, thereby enabling the conversion between listJsonTree and JSON strings.

[0115] Thirdly, it supports random modification of the value of a key in any JSON format.

[0116] Point 4: Read the interface documentation information into JsonTree.

[0117] In this application embodiment, for points 1 and 2, it is necessary to ensure their feasibility and correctness, and to ensure that JSON format information is not missing or disordered during the information conversion process.

[0118] When traversing the JSON string, a recursive approach is used to retrieve each element of different types layer by layer in sequence, recording the parent node, node, node value, node type (basic types such as JSONObject, JSONArray, String, etc.), and element index of the JSONArray for each element.

[0119] As mentioned above, the class variable (JsonTree) that records JSON information includes parent, key, value, type, and index.

[0120] The traversed information is stored in a collection (listJsonTree) of the JsonTree class. Then, the JSON string is restored from listJsonTree (or the value of a key is modified). Finally, the original JSON string and the two JSON strings restored from listJsonTree are sorted and compared. If they are the same, it means that the converted JSON information is complete and no data is lost after restoration. Furthermore, the system verifies nested JSON strings using JSONArray and JSONObject.

[0121] In this embodiment, points 3 and 4 can be implemented similarly to point 2, because the process of restoring from listJsonTree involves adding and assigning values ​​to keys at a specific location; if the value is null, it indicates deletion. A detailed flowchart can be found here. Figure 2 .

[0122] During the process of restoring the JSON string from listJsonTree, listJsonTree is looped, that is, restored element by element in order from the first position. For each key, its parent series table is generated first, and then the position of the element to be operated on (creating JSONObject / creating JSONArray / remove / put) is located according to the parent series table, and finally the operation is performed.

[0123] This embodiment provides a data processing method. The specific implementation of the aforementioned embodiments has been described in detail through the above embodiments. It can be seen from this that the data processing method proposed in this embodiment can realize the mutual conversion between JSON strings (such as interface documents) and JSON tree collections. Moreover, it can realize the random editing and automatic generation of JSON strings through JSON tree collections. It can automatically construct and modify the value of any node based on the interface document, or modify the value of any node through existing JSON string data. As a result, the amount of code is greatly reduced and the efficiency is greatly improved when writing interface automation test cases.

[0124] In another embodiment of this application, see [reference needed]. Figure 3 This illustrates a schematic diagram of the composition of a data processing apparatus 30 provided in an embodiment of this application. For example... Figure 3 As shown, the data processing device 30 may include a determining unit 301, a generating unit 302, and an operating unit 303, wherein...

[0125] The determining unit 301 is configured to determine a set of JSON trees; wherein the set of JSON trees includes at least one JSON tree, and each JSON element corresponds to one JSON tree; and if there are unprocessed JSON trees in the set of JSON trees, to determine a JSON tree to be processed from the unprocessed JSON trees.

[0126] The generation unit 302 is configured to generate a parent series table of the nodes based on the nodes in the JSON tree to be processed;

[0127] The operation unit 303 is configured to locate the position to be operated based on the parent series table and execute the operation command corresponding to the position to be operated.

[0128] In some embodiments, the determining unit 301 is specifically configured to obtain a first JSON file; wherein the first JSON file includes at least an interface document or a JSON string; and read the interface document or traverse the JSON string to obtain at least one JSON element; and generate at least one JSON tree based on the at least one JSON element; and determine the JSON tree set based on the at least one JSON tree.

[0129] In some embodiments, the generation unit 302 is specifically configured to obtain element information corresponding to each JSON element in the at least one JSON element; and generate a JSON tree corresponding to each JSON element based on the element information corresponding to each JSON element, so as to obtain the at least one JSON tree.

[0130] In some embodiments, the element information includes at least one of the following: parent node, node, node value, node type, and element index in the JSON array; wherein the node type includes at least one of the following: JSON object, JSON array, and string.

[0131] In some embodiments, such as Figure 4 As shown, the data processing device 30 may further include a judgment unit 304, configured to determine whether there is an unprocessed JSON tree in the JSON tree set; and if there is an unprocessed JSON tree in the JSON tree set, to perform the step of determining the JSON tree to be processed from the unprocessed JSON tree; and if there is no unprocessed JSON tree in the JSON tree set, to restore the JSON element corresponding to the position to be operated on and generate a second JSON file.

[0132] In some embodiments, such as Figure 4 As shown, the data processing device 30 may further include a comparison unit 305, configured to sort and compare the first JSON file and the second JSON file, and determine a comparison result; wherein the JSON tree set is generated based on the first JSON file; and if the comparison result indicates that the first JSON file and the second JSON file are the same, then it is determined that the JSON tree set information is complete and that the second JSON file has no information loss; and if the comparison result indicates that the first JSON file and the second JSON file are different, then it is determined that the JSON tree set information is incomplete, and / or, it is determined that the second JSON file has information loss.

[0133] In some embodiments, the operation unit 303 is specifically configured to execute a command to create a JSON object, and / or execute a command to create a JSON array, and / or modify the value of a node, and / or delete the value of a node at the location to be operated.

[0134] Understandably, in this embodiment, a "unit" can be a portion of a circuit, a portion of a processor, a portion of a program or software, etc., and can also be a module or a non-modular component. Furthermore, the components in this embodiment can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional module.

[0135] If the integrated unit is implemented as a software functional module and not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the method described in this embodiment. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0136] Therefore, this embodiment provides a computer storage medium storing a computer program that, when executed by at least one processor, implements the steps of any of the data processing methods described in the foregoing embodiments.

[0137] Based on the above-described composition of a data processing device 30 and a computer storage medium, see [link to relevant documentation]. Figure 5 This illustrates a schematic diagram of the structural composition of an electronic device 50 provided in an embodiment of this application. For example... Figure 5 As shown, it may include: a communication interface 501, a memory 502, and a processor 503; the various components are coupled together through a bus system 504. It is understood that the bus system 504 is used to implement communication between these components. In addition to a data bus, the bus system 504 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 6 All buses are labeled as bus system 504. Among them, communication interface 501 is used for receiving and sending signals during information exchange with other external network elements;

[0138] Memory 502 is used to store computer programs that can run on processor 503;

[0139] Processor 503, when running the computer program, performs the following:

[0140] Determine a set of JSON trees; wherein the set of JSON trees includes at least one JSON tree, and each JSON element corresponds to one JSON tree;

[0141] If there are unprocessed JSON trees in the JSON tree set, determine the JSON tree to be processed from the unprocessed JSON trees;

[0142] Generate a parent series table for each node based on the nodes in the JSON tree to be processed;

[0143] Locate the position to be operated on based on the parent series table, and execute the operation command corresponding to the position to be operated on.

[0144] It is understood that the memory 502 in the embodiments of this application can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DRRAM). The memory 502 of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0145] The processor 503 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of the processor 503 or by instructions in software form. The processor 503 can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory 502, and the processor 503 reads the information in memory 502 and, in conjunction with its hardware, completes the steps of the above method.

[0146] It is understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described herein, or combinations thereof.

[0147] For software implementation, the techniques described herein can be achieved through modules (e.g., procedures, functions, etc.) that perform the functions described herein. The software code can be stored in memory and executed by a processor. The memory can be implemented within the processor or externally.

[0148] Alternatively, as another embodiment, the processor 503 is also configured to perform the method described in any of the foregoing embodiments when running the computer program.

[0149] Based on the composition of the data processing device 30 described above, see [link to relevant documentation]. Figure 6 This illustrates a schematic diagram of the structural composition of another electronic device 50 provided in an embodiment of this application. For example... Figure 6 As shown, the electronic device 50 includes at least the data processing device 30 described in any of the foregoing embodiments.

[0150] For electronic device 50, since the position to be operated on in the JSON tree set can be located according to the parent series table of the node and the corresponding operation command can be executed, the JSON data can be automatically generated and randomly edited according to the JSON tree set, and there is no need to manually repeat the tedious writing and modification actions, thereby improving the efficiency of writing and modifying JSON data.

[0151] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application.

[0152] It should be noted that, in this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0153] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0154] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0155] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.

[0156] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.

[0157] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A data processing method, characterized in that, The method includes: Determine a set of JSON trees; wherein the set of JSON trees includes at least one JSON tree, and each JSON element corresponds to one JSON tree; If there are unprocessed JSON trees in the JSON tree set, determine the JSON tree to be processed from the unprocessed JSON trees; Generate a parent series table for each node based on the nodes in the JSON tree to be processed; Locate the position to be operated on based on the parent series table, and execute the operation command corresponding to the position to be operated on; The determination of the JSON tree set includes: Obtain the first JSON file; wherein the first JSON file includes at least an interface document or a JSON string; Read the interface document or iterate through the JSON string to obtain at least one JSON element; Generate at least one JSON tree based on the at least one JSON element; The set of JSON trees is determined based on the at least one JSON tree.

2. The method according to claim 1, characterized in that, The step of generating at least one JSON tree based on the at least one JSON element includes: Obtain the element information corresponding to each JSON element in the at least one JSON element; Based on the element information corresponding to each JSON element, generate a JSON tree corresponding to each JSON element to obtain the at least one JSON tree.

3. The method according to claim 2, characterized in that, The element information includes at least one of the following: parent node, node, node value, node type, and element index in the JSON array; wherein the node type includes at least one of the following: JSON object, JSON array, and string.

4. The method according to claim 1, characterized in that, After determining the JSON tree set, the method further includes: Determine whether an unprocessed JSON tree exists in the JSON tree collection; If there are unprocessed JSON trees in the JSON tree set, then the step of determining the JSON tree to be processed from the unprocessed JSON trees is performed; If there is no unprocessed JSON tree in the JSON tree set, then the JSON element corresponding to the position to be operated on is restored, and a second JSON file is generated.

5. The method according to claim 4, characterized in that, After generating the second JSON file, the method further includes: The first JSON file and the second JSON file are sorted and compared to determine the comparison result; wherein, the JSON tree set is generated based on the first JSON file. If the comparison result indicates that the first JSON file and the second JSON file are the same, then it is determined that the JSON tree set information is complete and that the second JSON file has no missing information. If the comparison result indicates that the first JSON file and the second JSON file are different, then it is determined that the JSON tree set information is incomplete, and / or, it is determined that the second JSON file has missing information.

6. The method according to any one of claims 1 to 5, characterized in that, The execution of the operation command corresponding to the position to be operated on includes: At the location to be operated, execute the command to create a JSON object, and / or execute the command to create a JSON array, and / or modify the value of a node, and / or delete the value of a node.

7. A data processing apparatus, characterized in that, The data processing device includes a determining unit, a generating unit, and an operating unit, wherein... The determining unit is configured to determine a set of JSON trees; wherein the set of JSON trees includes at least one JSON tree, and each JSON element corresponds to one JSON tree; and if there are unprocessed JSON trees in the set of JSON trees, to determine a JSON tree to be processed from the unprocessed JSON trees. The generation unit is configured to generate a parent series table of the nodes based on the nodes in the JSON tree to be processed; The operation unit is configured to locate the position to be operated based on the parent series table and execute the operation command corresponding to the position to be operated. The determining unit is specifically configured as follows: Obtain the first JSON file; wherein the first JSON file includes at least an interface document or a JSON string; Read the interface document or iterate through the JSON string to obtain at least one JSON element; Generate at least one JSON tree based on the at least one JSON element; The set of JSON trees is determined based on the at least one JSON tree.

8. An electronic device, characterized in that, The electronic device includes a memory and a processor, wherein, The memory is used to store computer programs that can run on the processor; The processor is configured to execute the data processing method as described in any one of claims 1 to 6 when running the computer program.

9. A computer storage medium, characterized in that, The computer storage medium stores a computer program that, when executed by at least one processor, implements the data processing method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • JSON data editing method, device and system

    CN109800388A