WO2023273218A1 - Json packet checking method and json packet checking apparatus - Google Patents

Json packet checking method and json packet checking apparatus Download PDF

Info

Publication number
WO2023273218A1
WO2023273218A1 PCT/CN2021/139563 CN2021139563W WO2023273218A1 WO 2023273218 A1 WO2023273218 A1 WO 2023273218A1 CN 2021139563 W CN2021139563 W CN 2021139563W WO 2023273218 A1 WO2023273218 A1 WO 2023273218A1
Authority
WO
WIPO (PCT)
Prior art keywords
message
value
source
target
json
Prior art date
Application number
PCT/CN2021/139563
Other languages
French (fr)
Chinese (zh)
Inventor
夏柱昌
夏勇
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2023273218A1 publication Critical patent/WO2023273218A1/en

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L9/00Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
    • H04L9/32Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
    • H04L9/3236Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions
    • H04L9/3239Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions involving non-keyed hash functions, e.g. modification detection codes [MDCs], MD5, SHA or RIPEMD
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]

Definitions

  • This application relates to the technical field of financial technology (Fintech), in particular to a method for checking JSON messages and a device for checking JSON messages.
  • Json Java Script Object Notation, JS object notation, a lightweight data exchange format, JS is called Java Script, which is a programming language
  • Java Script Java Script
  • All of them have a very wide range of applications, especially for Java (an object-oriented programming language) application development and data testing, check whether the JSON messages before and after the interface change are consistent, and whether the JSON messages of the same data source are processed by multiple parties Whether the returned data is consistent, etc., are all necessary and frequent operations.
  • JSON message checking method is to use tools such as Beyond Compare (a text file comparison tool) or based on a simple Json open source package to compare data consistency.
  • Beyond Compare a text file comparison tool
  • these checking methods cannot implement data consistency checks in situations where the data nesting level of the JSON message itself is deep, fields change, or there is an unsorted data list in the JSON message, resulting in low efficiency of the JSON message consistency check.
  • the main purpose of this application is to propose a JSON message checking method and a JSON message checking device, aiming at solving the existing technical problem of low checking efficiency for JSON message consistency checking.
  • the application provides a checking method of a JSON message, and the checking method of the JSON message includes the following steps:
  • Checking is performed according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
  • the present application also provides a JSON message checking device, the JSON message checking device includes:
  • a message check preparation module configured to obtain a JSON message to be checked and a preset message check rule, wherein the message check rule is configured based on the JSON message to be checked;
  • a message conversion module configured to convert the first source message in the JSON message to be checked into the second source message of the Map data structure, and convert the first target message in the JSON message to be checked Be converted into the second target message of Map data structure;
  • a Value determination module configured to determine the source Value from the second source message according to the message checking rules if the MD5 values of the second source message and the second target message are inconsistent after comparison value, and determine the target Value value from the second target message according to the message checking rule;
  • a checking module configured to check according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
  • each functional module of the device for checking JSON messages in the present application implements the steps of the checking method for JSON messages as described above during operation.
  • the present application also provides a terminal device, which includes: a memory, a processor, and a check program for JSON messages stored on the memory and operable on the processor, When the checking program of the JSON message is executed by the processor, the above-mentioned steps of the checking method of the JSON message are realized.
  • the present application also provides a computer storage medium, the computer storage medium is stored with a check program for JSON messages, and when the check program for JSON messages is executed by a processor, the above-mentioned The steps of the verification method of the JSON message.
  • the present application also provides a computer program product, the computer program product includes a check program for JSON messages, and when the check program for JSON messages is executed by a processor, the above-mentioned JSON message is implemented.
  • the steps of the verification method of the document includes a check program for JSON messages, and when the check program for JSON messages is executed by a processor, the above-mentioned JSON message is implemented.
  • the present application obtains the JSON message to be checked and the preset message checking rule, wherein, the message checking rule is configured based on the JSON message to be checked; the first in the JSON message to be checked The source message is converted into the second source message of the Map data structure, and the first target message in the JSON message to be checked is converted into the second target message of the Map data structure; The MD5 value of the second source message is inconsistent with the second target message, then determine the source Value value from the second source message according to the message checking rule, and determine the source Value value from the second source message according to the message checking rule Determining a target Value in the second target message; checking according to the source Value and the target Value to obtain a message check result of the unchecked JSON message.
  • this application converts the JSON message into a Map data structure, and according to the pre-configured message check rules based on The Map data structure determines the Value value to check the consistency of the message. In this way, it can realize convenient and accurate processing and checking of any field of the JSON message, effectively avoiding the situation that the traditional method cannot be checked, and improving the JSON report. The efficiency of document consistency check.
  • Fig. 1 is the schematic structural diagram of the verification device of the JSON message of the hardware operating environment involved in the scheme of the embodiment of the present application;
  • Fig. 2 is the schematic flow chart of the checking method one embodiment of the JSON message of the present application
  • Fig. 3 is the description of fields in the message checking rules involved in an embodiment of the checking method of the JSON message of the present application
  • Fig. 4 is the data table associated with the preset checking application involved in an embodiment of the checking method of the JSON message of the present application
  • Fig. 5 is a schematic diagram of the application process involved in an embodiment of the checking method of the JSON message of the present application
  • FIG. 6 is a block diagram of an embodiment of a device for checking JSON messages of the present application.
  • FIG. 1 is a schematic structural diagram of a terminal device in a hardware operating environment involved in the solution of the embodiment of the present application.
  • the terminal device in this embodiment of the present application is a terminal device configured to check the consistency of the JSON message.
  • the terminal device may be a PC, a smart phone, or a server device on which a virtual machine runs.
  • the terminal device may include: a processor 1001 , such as a CPU, a network interface 1004 , a user interface 1003 , a memory 1005 , and a communication bus 1002 .
  • the communication bus 1002 is used to realize connection and communication between these components.
  • the user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
  • the network interface 1004 may include a standard wired interface and a wireless interface (such as a WI-FI interface).
  • the memory 1005 can be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory.
  • the memory 1005 may also be a storage device independent of the aforementioned processor 1001 .
  • the structure of the terminal device shown in FIG. 1 does not constitute a limitation on the device, and may include more or less components than those shown in the figure, or combine some components, or arrange different components.
  • the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a checking program for JSON messages.
  • the network interface 1004 is mainly used to connect the background server and carry out data communication with the background server;
  • the user interface 1003 is mainly used to connect the client (client) and carry out data communication with the client;
  • the device 1001 can be used to call the verification program of the JSON message stored in the memory 1005, and perform the operations in the following JSON message verification method.
  • Json Java Script Object Notation, JS object notation, a lightweight data exchange format, JS is called Java Script, which is a programming language
  • Java Script Java Script
  • JSON message checking method is to use tools such as Beyond Compare (a text file comparison tool) or based on a simple Json open source package to compare data consistency.
  • Beyond Compare a text file comparison tool
  • these checking methods cannot implement data consistency checks in situations where the data nesting level of the JSON message itself is deep, fields change, or there is an unsorted data list in the JSON message, resulting in low efficiency of the JSON message consistency check.
  • FIG. 2 is a schematic flow chart of the first embodiment of the method for checking JSON messages of this application, the method for checking JSON messages of this application is applied to
  • the checking method of the JSON message in this application includes:
  • Step S10 obtaining the JSON message to be checked and a preset message checking rule, wherein the message checking rule is configured based on the JSON message to be checked;
  • the preset message checking rules are pre-configured and generated based on the JSON message to be checked, and stored in the corresponding checking rule base, so as to perform consistent
  • the checking rule base may be MySQL (a relational database management system) or SQLite (a light database) maintained in the local storage space of the terminal device.
  • the terminal device obtains the JSON message to be checked that currently needs to be checked for consistency from the database storing the JSON message, and obtains the consistency check for the JSON message to be checked from the check rule library that stores message checking rules. Checked packet check rules.
  • the database storing JSON messages is a specific storage space independently configured on the terminal side in the local storage space and named "JSON message library".
  • the space can also be maintained as MySQL or SQLite.
  • the terminal device will write the JSON messages generated during development, testing and even operation into the "JSON message library”.
  • a request for consistency check of the source message and target message generated before and after a certain interface change, that is, the source message and target message are regarded as the JSON message to be checked, and the JSON message library is obtained from the "JSON message library".
  • the JSON message to be checked is ready for subsequent consistency check.
  • the terminal device obtains the JSON message to be checked from the "JSON message library", it also synchronously obtains the pre-configured generation based on the JSON message to be checked in the "checking rule base" for use in Check the message checking rules to check whether the source message and the target message in the JSON message to be checked are consistent.
  • the checking method of the JSON message of the present application may also include:
  • Step S50 generating a message checking rule for performing consistency check on the JSON message to be checked based on the configuration of the JSON message to be checked.
  • the terminal device After the terminal device receives the request for consistency check on the JSON message and determines the JSON message to be checked pointed to by the request, it immediately generates a consistency check message based on the configuration of the JSON message to be checked.
  • the message check rule of the sex check is used, and the message check rule is stored for calling.
  • the terminal device after the terminal device generates a message checking rule for consistency checking of the JSON message to be checked based on the configuration of the JSON message to be checked, it can follow the received JSON message The time of the request for the consistency check of the message, and the message check rule is stored in the check rule base. In this way, when the terminal device starts to check the consistency of the JSON message to be checked, it can accurately extract the message checking rule from the checking rule base according to the requested time and use it to perform consistency check on the JSON message to be checked. gender check.
  • the terminal device after the terminal device is configured to generate a message checking rule for consistency checking of the JSON message to be checked, it can also directly store the message checking rule in the checking rule base according to the current time, so that the terminal device When the consistency check for the JSON message to be checked is started immediately based on the request, the terminal device can extract the latest message check rule from the check rule base according to the current time for the consistency check of the JSON message to be checked gender check.
  • the terminal device can be set to respond to the next new request after executing the current request Request), so that no other message checking rules are configured and generated after the current time, then the latest message checking rules generated by the current configuration are the rules used to check the consistency of the JSON message to be checked.
  • the above step S50 based on the configuration of the JSON message to be checked, generates a message checking rule for performing consistency check on the JSON message to be checked, which may include:
  • Step S501 obtaining a preset message checking requirement, and analyzing the data structure of the JSON message to be checked;
  • the terminal device In the process of determining the to-be-checked JSON message that currently needs to be checked for consistency, and thereby generating a message checking rule based on the configuration of the to-be-checked JSON message, the terminal device first obtains the report for the consistency check of the to-be-checked JSON message document verification requirements, and synchronously parse the data structure of the JSON message to be verified.
  • the terminal device can obtain the message checking requirements for consistency checking from the received request for consistency checking on JSON messages to be checked, and the message checking requirements include but Not limited to: comparing fields directly, comparing arrays, and comparing arrays within arrays.
  • the terminal device receives a request for consistency comparison between the source message and the target message before and after a certain interface change, and determines the source message and the target message together as the JSON to be checked After the message, the terminal device further determines from the request based on the mature command analysis technology that the current message check requirement for the consistency check of the JSON message to be checked is to directly compare fields, compare arrays, or compare arrays in arrays. Moreover, based on the mature data structure analysis technology, the terminal device analyzes and determines the data structures such as all the fields contained in the source message and the target message respectively.
  • Step S502 generate a message checking rule corresponding to the data structure according to the message checking requirement configuration and used for checking the consistency of the JSON message to be checked.
  • the terminal device After the terminal device obtains the message verification requirement for the consistency check of the JSON message to be checked, and parses out the data structure of the JSON message to be checked, it configures and generates the corresponding data structure according to the message checking requirement. Therefore, it can be used as a message checking rule for accurately checking the consistency of the checking JSON message.
  • to_path target.x.y
  • the terminal device parses and obtains all the fields contained in the source message and the target message, it can be configured to generate corresponding to all the fields so that it can be used to accurately check the source message and the target message
  • the message check rule for target message consistency is: INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark)VALUES('T3_ACCT_INFO_NEW_ALUE02','FO3_UEW_IN' 'custNumber','CUST_NUMBER','N','N',”,”,”,'Compare T3accountInfos external content').
  • the terminal device obtains the message verification requirement from the request for consistency check of the JSON message to be checked: compare the arrays of the source message and the target message, so as to determine the message generated by the required configuration.
  • the name of the array needs to be configured, and the fields that do not want to be compared in the array can be configured in "sys_rmb_compare_def.ignore_field_from” and "sys_rmb_compare_def.ignore_fieldto”, and the terminal device parses and obtains that the source message and the target message respectively contain After all the fields, you can configure and generate a packet check rule that corresponds to all the fields and can be used to accurately check the consistency between the source packet and the target packet: INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path ,to_path,check_first_only_if_list,check_size_if_list,from_check_fields
  • the terminal device obtains the message verification requirement from the request for consistency check of the JSON message to be checked: compare the array within the array for the source message and the target message, so as to determine the required configuration
  • "#" needs to be used to separate the arrays of different nesting levels, and after the terminal device parses and obtains all the fields contained in the source message and the target message, it can be configured to generate and match all the fields.
  • the message check rule that corresponds to the field and can be used to accurately check the consistency between the source message and the target message is: INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark )VALUES('T3_ACCT_INFO_NEW_03','T3_ACCT_INFO_NEW','LIST_LIST','accountInfos#subAccountInfo','ACCOUNT_INFOS#SUB_ACCOUNT_INFO','N','N',
  • the data structure of the JSON message to be checked is synchronously analyzed by obtaining the message checking requirement for the consistency check of the JSON message to be checked, thereby configuring and generating the data according to the message checking requirement.
  • the structure corresponds to the message checking rule that can be used to accurately check the consistency of the checked JSON message.
  • this application does not require additional development work, and only dynamically configures the corresponding message according to the message verification requirements.
  • the text checking rules By using the text checking rules, the consistency checking of complex, customizable and multi-level JSON messages can be realized, which further improves the checking efficiency.
  • Step S20 converting the first source message in the JSON message to be checked into the second source message of the Map data structure, and converting the first target message in the JSON message to be checked into Map data the second target message of the structure;
  • the terminal device After obtaining the to-be-checked JSON message that needs to be checked for consistency, the terminal device further converts the first source message in the to-be-checked JSON message into the second source message of the Map data structure, and also The first target message in the to-be-checked JSON message is also converted into the second target message of the Map data structure.
  • the terminal device receives a request for consistency check of the source message and the target message generated before and after a certain interface change in the "JSON message library", so that the source message and the target message As the JSON message to be checked, and after obtaining the JSON message to be checked from the "JSON message library" to prepare for the consistency check, the terminal device will use the source message as the first source message to use the second A source message is converted into a second source message of the Map data structure, and the terminal device also uses the target message as the first target message to convert the first target message into the second target of the Map data structure message, so that the value value can be conveniently determined and compared with the second source message and the second target message according to the Map data structure.
  • the Map data structure includes: an ordinary Map data structure and a nested Map data structure, in step S20, "the first source in the JSON message to be checked
  • the step of converting the message into the "second source message of the Map data structure" may include:
  • Step S201 determining the first message data in common form and/or the second message data in nested form in the first source message
  • the terminal device converts the first source message in the JSON message to be checked into the second source message of the Map data structure, it first determines the first message data and/or The second packet data in nested form.
  • the first message data in common form is the message content in the form of K-V in the JSON message
  • the second message data in the nested form is the K-V form in the JSON message.
  • Step S202 converting the first message data into the second source message of the common Map data structure, and/or converting the second message data into the nested Map data structure second source message;
  • the terminal device After the first source message determines the first message data in common form and/or the second message data in nested form, the terminal device respectively performs Converting, that is, directly converting the first message data into a second source message of a common Map data structure, and/or correspondingly converting the second message data into a second source of a nested Map data structure message.
  • the common Map data structure is WeMap(K, V), and the message of the WeMap(K, V) can be obtained directly based on the value algorithm WeMap.get(K) to obtain the corresponding Value; while the nested Map data structure is WeMap(K,List(WeMap((K1,V1),(K2,V2), «))), the WeMap(K,List(WeMap((K1, V1), (K2, V2),...))) messages need the value algorithm corresponding to the nesting level to obtain the Value value of the corresponding nesting level, that is, get the corresponding value through WeMap.get(K.K1) V1, WeMap.get(K.K2) obtains the corresponding V2, and the List(WeMap((K1,V1),(K2,V2),...)) can be obtained through WeMap.get(K), where V1 , V2 respectively refer to the Value corresponding to the first level and the Value corresponding to the second level. By analogy, it can support the extraction of the corresponding Value
  • step S20 the step of "converting the first target message in the JSON message to be checked into the second target message of the Map data structure"
  • Step S203 determining the third message data in common form and/or the fourth message data in nested form in the first target message
  • the terminal device converts the first target message in the JSON message to be checked into the second target message of the Map data structure, it first determines the third message data in a common form in the first target message and/or Or the fourth message data in a nested form.
  • Step S204 converting the third message data into the second target message of the common Map data structure, and/or converting the fourth message data into the nested Map data structure Second target message.
  • the terminal device After the terminal device determines the third message data in common form and/or the fourth message data in nested form in the first target message, it respectively performs Converting, that is, directly converting the third message data into a second target message of a common Map data structure, and/or correspondingly converting the fourth message data into a second target of a nested Map data structure message.
  • step S204 the step of "converting the fourth message data into the second target message of the nested Map data structure" may include:
  • Step S2041 cyclically detect the Value value type corresponding to the key value in each nesting level of the fourth message data, wherein the Value value type includes: ordinary Value value, JSON array and JSON object;
  • the terminal device converts the message data in the nested form in the JSON message to be checked into a message of the nested Map data structure, it loops for each level to obtain the Key value , Obtain the Value value corresponding to the Key and determine the type of the Value value.
  • the terminal device performs, for each nesting level of the fourth message data, first obtaining the Key value, and then obtain the Value value corresponding to the Key, and determine whether the type of the Value value is a normal Value value, JSON array, or JSON object.
  • Step S2042 if it is detected that the type of the Value is the normal Value, record the key value as a Map data structure to obtain the second target message.
  • the terminal device determines that the type of the Value value is a normal Value value, the terminal device directly sets the value of the nesting level
  • the key value of the key is directly recorded as a Map data structure. In this way, after the key values of all nested levels are recorded as a Map data structure, the second goal of converting the fourth message data into a nested Map data structure is completed. message.
  • the terminal device loops through the operations of obtaining the Key value, obtaining the Value value corresponding to the Key, and judging the type of the Value value.
  • the type is a JSON array (Array)
  • the type of the Value value is a JSON object (Object)
  • further treat the Value value as a "Json object” and write the value in the Map data: (Key, toWeMap(Value)), so that it is called in subsequent processing
  • the terminal device can directly write the Value value into the Map data, that is, write the value in the Map data
  • toList is to parse all the Key-Values in the List type and store them in the Map data structure.
  • the terminal device After the terminal device judges that the type of the Value value is a JSON array (Array), it further uses the Value value as a "List type" to enter the next level of loop processing, and writes the value in the Map data: (Key,toList( Value)), further call the "toList” to start recirculation execution for each value in the List: the operation of obtaining the Value value and judging the type of the Value value, and, similarly, the terminal device is judging the type of the Value value , if it is judged that the type of the Value value is a Json array, then continue to use the Value value as a "List type” to enter the next level of loop processing, and the List writes the value: (toList(Value)), so, you can Recursively call "toList” to recursively process the value inside the List; and when it is judged that the type of the Value value is a Json object, the Value is treated as a Json object, and the value is written into the List: (toWeMap(Value)),
  • the process that the terminal device converts the second message data in the nested form into the second source message of the nested Map data structure is the same as converting the fourth message data in the nested form into the nested Map data.
  • the process of the second target packet of the structure is the same, and will not be repeated here.
  • Step S30 if the MD5 values of the second source message and the second target message are inconsistent according to the comparison, then determine the source Value value from the second source message according to the message checking rule, and determining a target Value from the second target message according to the message checking rule;
  • the terminal device converts the first source message and the first target message in the JSON message to be checked into the second source message and the second target message of the Map data structure, and then first targets the second source message
  • the message and the second target message are compared with the MD5 value of the whole text, so that when the MD5 values of the second source message and the second target message are not the same, further according to the acquired Based on the message checking rule for consistency checking of the JSON message to be checked, the source Value is determined in the second source message, and the target Value is determined in the second target message for subsequent checking.
  • the terminal device compares the MD5 value of the whole text of the second source message and the second target message, and compares the second source message and the second target message When the MD5 values of the two target messages are the same, the terminal device can directly obtain the message checking result of the successful consistency check between the source message and the target message in the JSON message to be checked.
  • Step S40 check according to the source Value and the target Value to obtain a message check result of the JSON message to be checked.
  • the terminal device After determining the source value in the second source message and determining the target value in the second target message, the terminal device compares whether the source value and the target value are the same, and determines the corresponding Simultaneously, in the JSON message to be checked, the message checking result of the consistency check of the source message and the target message is obtained correspondingly; otherwise, when it is determined that they are different, correspondingly, in the JSON message to be checked, The check result of the message that the consistency check between the source message and the target message fails.
  • step 2 in the example of the terminal device performing a consistency check on the JSON message to be checked through the verification application (the verification APP shown in the figure) in the application process shown in Figure 5.
  • the terminal device passes the verification application
  • the source Value corresponding to the same Key is determined from the second source message and the second target message directly according to the value path corresponding to the Value type in the message check rule value and the target Value value
  • the terminal device compares whether the source Value value is the same as the target Value value, and if the source Value value is the same as the target Value value, it obtains the current verification according to the message
  • the rule checks the consistency of the JSON message to be checked, and the message check result is successful. On the contrary, if the source value and the target value are not the same, the message check result is failed, and the failure is recorded s reason.
  • the source value includes: an inner source value
  • the target value includes: an inner target value
  • Step S301 determining the first value path corresponding to the preset Value message check type in the message check rule
  • the terminal device may specifically acquire the preset Value message check type by parsing the received request for consistency check on the JSON message to be checked.
  • the terminal device determines the source value and the target value from the second source message and the second target message respectively according to the obtained message check rule, if the value obtained for the consistency check of the JSON message to be checked is Message check type, then according to the Value message check type in the second source message and the second target message, it is determined to be corresponding to the Value type for extracting the inner layer source Value value and the inner layer target Value The first value path for the value.
  • Step S302 determining the inner source Value value from the second source message according to the first value path, and determining the inner layer value from the second target message according to the value path Target Value.
  • the terminal device determines the first value path from the message verification rules according to the type of the Value message verification, it further obtains the innermost content in the multi-level second source message according to the first value path.
  • the layer source Value value and also obtain the innermost layer target Value value in the multi-level second target message according to the first value acquisition path.
  • the second source message of the Map data structure obtained by converting the first source message in the JSON message to be checked by the terminal device is: WeMap(K,List(WeMap(K1,List(WeMap( (K2,V2),(K3,V3),...)))))).
  • the terminal device obtains the Value message check type, and uses the Value message check type to determine the first value path from the message check rules: Key is K.K1.K2, then the terminal device directly According to the Key is K.K1.K2 from the second source message: WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),...)))))) , get the innermost V2 as the inner source Value.
  • the terminal device may obtain the innermost inner target Value from the second target packet.
  • step S40 may include:
  • Step S401 comparing the inner source Value with the inner target Value to obtain a comparison result
  • Step S402 if the comparison result is that the inner source Value and the inner target Value are the same, then obtain a message check result indicating that the consistency check of the to-be-checked JSON message is successful.
  • the terminal device follows the first value path: Key is K.K1.K2, and from the second source message: WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),( In K3,V3),...)))), the innermost V2 is obtained as the inner source Value value, and, according to the first value path: Key is K.K1.K2, from the The second target message with the same Map data structure in the second source message obtains the innermost inner target Value value, and then the terminal device compares whether the inner source Value value is the same as the inner target Value value, And, when comparing the source value of the inner layer with the target value of the inner layer, it is obtained that the message checking result of the consistency checking of the JSON message to be checked according to the message checking rule is successful, and the opposite , if the source value is not the same as the target value, the message check result is failed, and the reason for the failure is recorded.
  • the source Value includes: a first source field Value
  • the target Value includes: a first target field Value
  • the above step S30 may also include:
  • Step S303 determining the second value path corresponding to the preset List message check type in the message check rule
  • the terminal device may specifically obtain the preset List message check type by parsing the received request for consistency check on the JSON message to be checked.
  • the terminal device determines the source value and the target value from the second source message and the second target message respectively according to the obtained message checking rules, if it obtains the List for consistency check for the JSON message to be checked Message check type, then according to the List message check type in the second source message and the second target message, determine that it is corresponding to the List type for extracting the first source field Value value and the first target The second path to obtain the value of the field Value.
  • Step S304 Determine the value of the first source field Value from each piece of source message data in the second source message according to the second value path, and determine the value of the first source field Value from the first value path according to the second value path.
  • the value of the first target field Value is determined in each piece of source message data of the second target message.
  • the terminal device After the terminal device determines the second value path from the message verification rules according to the type of the List message check, it further selects among the source message data of the multi-level second source message according to the second value path. , to obtain the first source field Value value of each level of source message data, and, also according to the second value path, among the source message data of the multi-level second target message, to obtain each Value of the first target field of hierarchical source packet data.
  • the second source message of the Map data structure obtained by the terminal device by converting the first source message in the JSON message to be checked is WeMap(K, List(WeMap((K1 ,V1),(K2,V2), etc)).
  • the terminal device obtains the Value message check type, and uses the List message check type to determine the second value path from the message check rules: Key is K, then the terminal device directly follows the Key as K obtains the first source message data corresponding to the outermost List from the second source message: WeMap(K,List(WeMap((K1,V1),(K2,V2),...)))
  • the source field Value value is: List(WeMap((K1,V1),(K2,V2),...)), and so on to obtain the first source field Value value of all the source message data corresponding to each level of List.
  • the terminal device may obtain the Value of the first target field of each level of source message data from each piece of source message data in the second target message.
  • step S40 may also include:
  • Step S403 sorting each of the source message data and each of the target message data according to the sorting manner corresponding to the List type in the message checking rule;
  • the terminal device may configure a sorting field in the message checking rule based on the received request for consistency checking on the JSON message to be checked.
  • the terminal device After the terminal device obtains the first source field Value value of the source message data corresponding to each layer List of the second source message, and the target message data corresponding to each layer List of the second target message After the value of the first target field Value, the terminal device first sorts the multiple pieces of message data in the List of each level according to the sorting field configured in the message checking rule to obtain the sorted message data.
  • Step S404 checking whether the number of the first data pieces of each of the sorted source message data and each of the target message data is consistent;
  • the terminal device sorts each piece of source message data and each piece of target message data, the first data number of each piece of source message data and each piece of target message data after the sorting is according to the message checking rule Is it consistent.
  • the terminal device After the terminal device respectively sorts the multiple pieces of message data in the List of each level according to the sorting field configured in the message checking rule to obtain the sorted message data, it detects the number of items in the message checking rule. Whether the check rule for the number of data items in the List is configured (assumed to be: check that the number of items in the source message data and the target message data are the same, or, check that the number of items in the source message data cannot be less than the number of target message data number of items, etc.), thus, if it is detected that the check rule is configured in the message check rule, the number of message data items in the List of each level corresponds to each target item after sorting the source message data. After the message data is sorted, compare the number of message data items in the list of each level to determine whether the numbers are the same. If they are not the same, return the verification failure and record the reason for the failure.
  • Step S405 if it is checked that the number of the first data items is consistent, then compare the value of the first source field Value with the value of the first target field;
  • Step S406 when the value of the first source field Value and the value of the first target field are the same after comparison, obtain a message check result indicating that the consistency check of the JSON message to be checked is successful.
  • the terminal device When the terminal device checks that the number of first data pieces of each piece of source message data and each piece of target message data is consistent after sorting, it further performs the determined first source field Value value and the first target field Value value. Compare; and when comparing the first source field Value value and the first target field Value value, correspondingly obtain the message that the consistency check of the source message and the target message is successful in the JSON message to be checked. Text check results.
  • the process for the terminal device to check whether the first source field Value and the first target field Value are consistent is the same as the above-mentioned process for checking whether the source Value and the target Value are consistent. I won't go into too much detail here.
  • the terminal device checks the first source field Value value and the first target field Value value it also checks whether there is a configuration that must check the first piece of data in the message check rule, and, similarly, if it exists but checks to The second source message and the second target message do not conform to the rules, and the result of the message check is failure, and the reason for the failure is recorded; and the terminal device checks for each source message data or target message in each layer List The data can be checked one by one according to the fields.
  • the source Value includes: a second source field Value
  • the target Value includes: a second target field Value.
  • the above step S30 may also include:
  • Step S305 determining the third value path corresponding to the preset List_List message checking type in the message checking rule
  • the terminal device may specifically obtain the preset List_List message check type by parsing the received request for consistency check on the JSON message to be checked.
  • the terminal device determines the source value and the target value from the second source message and the second target message respectively according to the obtained message checking rules, if it obtains the List_List for consistency checking of the JSON message to be checked Message check type, then according to the List_List message check type in the second source message and the second target message, determine that it is corresponding to the List_List type for extracting the second source field Value value and the second target The third value path of the value of the field Value.
  • Step S306 Determine the value of the second source field Value from each piece of source message data in the second source message according to the third value path, and determine the value of the second source field Value from the first value path according to the third path.
  • the value of the second target field Value is determined in each item of target message data of the second target message.
  • the terminal device determines the third value-taking path from the message checking rules according to the message checking type of List_List, that is, further according to the third value-taking path, among the source message data of the multi-level second source message , to obtain the second source field Value value of each level of source message data, and, also according to the third value path, among the source message data of the multi-level second target message, to obtain each The value of the second target field Value of the hierarchical source message data.
  • the second source message of the Map data structure obtained by the terminal device by converting the first source message in the JSON message to be checked is WeMap(K, List(WeMap) in the form of K, List(List) (K1,List(WeMap((K2,V2),(K3,V3), etc))))).
  • the terminal device obtains the List_List message check type, and uses the List_List message check type to determine the third value path from the message check rule: Key is K
  • the terminal device directly follows the Key as K obtains the second source message data corresponding to the outermost List from the second source message: WeMap(K,List(WeMap((K1,V1),(K2,V2),...))).
  • the Value value of the source field is: Value is List(K1,List(WeMap((K2,V2),(K3,V3), «))), and so on to get all the source message data corresponding to each level of List The value of the second source field.
  • the terminal device can obtain the value of the second target field of the source message data of each level from each piece of source message data in the second target message.
  • step S40 may also include:
  • Step S407 checking the second number of data pieces of the source message data and the target message data layer by layer from outside to inside according to the hierarchical order;
  • the hierarchical order is the hierarchical order of the respective message data in the second source message and the second target message indicated by each layer of List in the Map data structure, for example , when the second source message is WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),...))))))) in the form of K,List(List),
  • the outermost source message data indicated by List is: WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),...))))))))))))
  • the innermost source message data indicated by the List is: WeMap((K2, V2), (K3, V3),).
  • the terminal device detects whether a check rule for the number of data items in the List is configured in the message check rule, and when it detects that the check rule is configured in the message check rule, it checks each source message Data, according to the order of levels indicated by the List, the number of source message data in each level of List is compared with the number of target message data in each level of List to determine whether the numbers are the same, if If the number of checks is not the same, return check failure and record the reason for the failure.
  • Step S408 if it is checked that the number of the second data pieces is the same, compare the value of the second source field Value with the value of the second target field;
  • Step S409 when the value of the second source field Value and the value of the second target field are the same after comparison, obtain a message check result indicating that the consistency check of the JSON message to be checked is successful.
  • the terminal device checks layer by layer that the number of data pieces of each piece of source message data and each piece of target message data is consistent, it further compares the determined value of the second source field with the value of the second target field ; and when the second source field Value value is consistent with the second target field Value value, correspondingly obtain the message check that the consistency check between the source message and the target message is successful in the JSON message to be checked result.
  • the process for the terminal device to check whether the value of the second source field is consistent with the value of the second target field is the same as the process for checking whether the value of the source value and the target value are consistent. I won't go into too much detail here.
  • the terminal device checks the data in the inner List according to the hierarchical order it is based on List(WeMap(K1,List(Map((K2,V2),(K3,V3),...))))))))))))))))))),
  • K1 to determine the Value value is List(WeMap((K2,V2),(K3,V3),...)
  • the check rule is the same as the above terminal equipment in determining The verification process when the message verification type is List type.
  • the application JSON may also include:
  • Step S60 recording the message checking result in a data table associated with a preset checking application for output, wherein the running mode of the preset checking application is a background running mode; or,
  • Step S70 outputting the message checking result through a preset API.
  • the terminal device can perform the process of performing the consistency check for the JSON message to be checked in the above steps by checking that the application is running in the background.
  • the terminal device can also embed a functional business module, and the business module that performs the message checking function embedded in any application performs the above-mentioned steps to perform the process of consistency checking for the JSON message to be checked.
  • the terminal device After the terminal device checks the consistency of the JSON message to be checked in the background operation mode through the checking application and obtains the message checking result, it will directly record the checking result of the message in the data table associated with the checking application, and based on Display the data table to output the verification result of the message.
  • the terminal device After the terminal device performs the checking process of the JSON message to be checked based on the background operation mode through the checking application, and after obtaining the message checking result of the consistency check, the terminal device writes the message checking as shown in Figure 4 In the field "compare_status" of the message table (assumed to be named: sys_compare_payload) describing the checking application (when the message checking result is a failure, the checking exception information will be written in the field "error_msg", so that the message table When displaying, the verification result of the message can be output.
  • compare_status of the message table (assumed to be named: sys_compare_payload) describing the checking application (when the message checking result is a failure, the checking exception information will be written in the field "error_msg", so that the message table When displaying, the verification result of the message can be output.
  • the data table associated with the checking application can also be stored in MySQL or SQLLite like the checking rule library storing message checking rules or the JSON message library storing JSON messages.
  • the terminal device After the terminal device checks the consistency of the JSON message to be checked and obtains the message checking result through the business module embedded in the application that performs the message checking function, it will obtain the JSON message to be checked and the message checking result through the business module.
  • the application program interface enabled at the time of the rule directly feeds back the verification result of the message.
  • the terminal device uses the business module again to obtain the JSON message to be checked
  • the API interface the application program interface enabled when checking the rules with the message, directly returns the message check (when the message check result is a failure, the exception information is also checked synchronously through the API interface.
  • the terminal device when the terminal device outputs the message check result for the consistency check of the JSON message to be checked by checking the message table of the application or the application program interface of the business module, if the If the message verification result is failure, the terminal device can also synchronously issue an alarm for the inconsistency of the to-be-checked JSON message.
  • the terminal device can perform the process of checking the consistency of the JSON message to be checked in the above steps by checking that the application is running in the background, or the terminal device can also be embedded in a functional business module.
  • the business module that performs the message checking function embedded in any application executes the above-mentioned steps to check the consistency of the JSON message to be checked.
  • this application implements running in the background as an application to directly check the source JSON message and the target JSON message , or embedded into other applications, and perform data verification through the API interface, which improves the flexibility of JSON message consistency verification.
  • the checking method of the JSON message provided by this application is to obtain the JSON message to be checked that currently needs to be checked for consistency from the database storing the JSON message through the terminal device, and obtain from the checking rule base storing the message checking rules.
  • a message checking rule for consistency checking of the JSON message to be checked the first source message in the JSON message to be checked is converted into a second source message of the Map data structure, and the The first target message in the JSON message to be checked is also converted into the second target message of the Map data structure; according to the message checking rule obtained for the consistency check of the JSON message to be checked, Determine the source Value value in the second source message, and determine the target Value value in the second target message for subsequent checking; by comparing whether the source Value value and the target Value value are the same, and determine the corresponding Simultaneously, in the JSON message to be checked, the message checking result of the consistency check of the source message and the target message is obtained correspondingly; otherwise, when it is determined that they are different, correspondingly, in the JSON
  • this application converts the JSON message into a Map data structure, and according to the pre-configured message check rules based on The Map data structure determines the Value value to check the consistency of the message. In this way, it can realize convenient and accurate processing and checking of any field of the JSON message, effectively avoiding the situation that the traditional method cannot be checked, and improving the JSON report. The efficiency of document consistency check.
  • the present application also provides a checking device for a JSON message, please refer to Figure 6, the checking device for the JSON message includes:
  • the message check preparation module 10 is used to obtain the JSON message to be checked and a preset message check rule, wherein the message check rule is configured based on the JSON message to be checked;
  • Message conversion module 20 for converting the first source message in the JSON message to be checked into the second source message of the Map data structure, and converting the first target message in the JSON message to be checked The text is converted into the second target message of the Map data structure;
  • Value determination module 30 configured to determine the source from the second source message according to the message checking rules if the MD5 values of the second source message and the second target message are inconsistent after comparison Value value, and determine the target Value value from the second target message according to the message checking rule;
  • a checking module 40 configured to check according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
  • the source Value value includes: an inner layer source Value value
  • the target Value value includes: an inner layer target Value value
  • the Value determination module 30 includes:
  • a first path determination unit configured to determine a first value path corresponding to the preset Value message check type in the message check rule
  • a first Value determination unit configured to determine the inner source Value value from the second source message according to the first value path, and determine the inner source Value value from the second target message according to the value path determining the inner target Value;
  • Check module 40 including:
  • a first comparison unit configured to compare the inner source Value with the inner target Value to obtain a comparison result
  • the first result determination unit is configured to obtain a message that the consistency check of the JSON message to be checked is successful if the comparison result is that the inner source value and the inner target value are the same. Check the results.
  • the source Value value includes: a first source field Value value
  • the target Value value includes: a first target field Value value
  • the Value determination module 30 includes:
  • a second path determination unit configured to determine a second value path corresponding to the preset List message check type in the message check rule
  • a second Value determination unit configured to determine the value of the first source field Value from each piece of source message data in the second source message according to the second value path, and according to the second value path The path determines the value of the first target field Value from each piece of source message data in the second target message.
  • checking module 40 includes:
  • a sorting unit configured to sort each of the source message data and each of the target message data according to the sorting manner corresponding to the List type in the message checking rule;
  • a first checking unit configured to check whether the number of first pieces of data in each of the sorted source message data and each of the target message data is consistent
  • the second comparison unit is configured to compare the value of the first source field with the value of the first target field if the number of the first data pieces is checked to be consistent;
  • the second result determination unit is configured to obtain a message check that the consistency check of the JSON message to be checked is successful when the value of the first source field is the same as that of the first target field. result.
  • the source Value value includes: a second source field Value value
  • the target Value value includes: a second target field Value value
  • the Value determination module 30 includes:
  • a third path determination unit configured to determine a third value path corresponding to the preset List_List message check type in the message check rule
  • a third Value determination unit configured to determine the value of the second source field Value from each piece of source message data in the second source message according to the third value path, and according to the third value path The path determines the value of the second target field Value from each item of target message data in the second target message.
  • checking module 40 includes:
  • the second checking unit is configured to check the second number of data pieces of the source message data and the target message data layer by layer from outside to inside according to the hierarchical order;
  • a third comparison unit configured to compare the second source field Value with the second target field Value if the number of the second data pieces is found to be consistent
  • the third result determination unit is configured to obtain a message check that the consistency check of the JSON message to be checked is successful when the value of the second source field Value and the value of the second target field are the same after comparison. result.
  • checking device of the JSON message of the present application also includes:
  • a generating module configured to obtain a preset message checking requirement, and parse the data structure of the JSON message to be checked, so as to generate the data structure corresponding to the JSON message to be checked according to the message checking requirement. Packet checking rules for checking the consistency of the packets.
  • the device further includes:
  • the first output module is configured to record the message checking result in a data table associated with a preset checking application for output, wherein the running mode of the preset checking application is a background running mode; or,
  • the second output module is configured to output the message checking result through a preset application program interface.
  • Map data structure includes: a common Map data structure and a nested Map data structure
  • the message conversion module 20 is also used for:
  • the message conversion module 20 is also used for:
  • message conversion module 20 is also used for:
  • the Value value type includes: ordinary Value value, JSON array and JSON object;
  • the application also provides a checking device for a JSON message.
  • the checking device for a JSON message includes: a memory, a processor, and a checking program for a JSON message stored on the memory and operable on the processor.
  • the present application also provides a computer storage medium.
  • the checking program of the JSON message is stored on the computer storage medium of the application, and the checking program of the JSON message is implemented when the processor executes the steps of the checking method of the JSON message as described above.
  • the method implemented when the JSON message checking program running on the processor is executed can refer to the various embodiments of the JSON message checking method in this application, and will not be repeated here.
  • the present application also provides a computer program product.
  • the computer program product of the present application includes a JSON message checking program, and when the JSON message checking program is executed by a processor, the steps of the JSON message checking method described above are implemented.
  • the method implemented when the JSON message checking program running on the processor is executed can refer to the various embodiments of the JSON message checking method in this application, and will not be repeated here.
  • the term “comprises”, “comprises” or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article or system comprising a set of elements includes not only those elements, It also includes other elements not expressly listed, or elements inherent in the process, method, article, or system. Without further limitations, an element defined by the phrase “comprising a " does not preclude the presence of additional identical elements in the process, method, article or system comprising that element.
  • the methods of the above embodiments can be implemented by means of software plus a necessary general-purpose hardware platform, and of course also by hardware, but in many cases the former is better implementation.
  • the technical solution of the present application can be embodied in the form of a software product in essence or the part that contributes to the prior art, and the computer software product is stored in a storage medium as described above (such as ROM/RAM , magnetic disk, optical disk), including several instructions to make a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) execute the methods described in various embodiments of the present application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The present application relates to the technical field of financial technology (Fintech), and discloses a JSON packet checking method and a JSON packet checking apparatus. The method comprises: acquiring a JSON packet to be checked and a preset packet checking rule, wherein the packet checking rule is obtained by configuring on the basis of the JSON packet to be checked; converting a first source packet in the JSON packet to be checked into a second source packet of a Map data structure, and converting a first target packet in the JSON packet to be checked into a second target packet of the Map data structure; if a MD5 value of the second source packet is inconsistent with a MD5 value of the second target packet after comparison, determining a source Value from the second source packet according to the packet checking rule, and determining a target Value from the second target packet according to the packet checking rule; and performing checking according to the source Value and the target Value to obtain a packet checking result of the JSON packet to be checked.

Description

JSON报文的核对方法和JSON报文的核对装置Method for checking JSON message and device for checking JSON message
优先权信息priority information
本申请要求于2021年6月30日申请的、申请号为202110746878.X的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with application number 202110746878.X filed on June 30, 2021, the entire contents of which are incorporated in this application by reference.
技术领域technical field
本申请涉及金融科技(Fintech)技术领域,尤其涉及JSON报文的核对方法和JSON报文的核对装置。This application relates to the technical field of financial technology (Fintech), in particular to a method for checking JSON messages and a device for checking JSON messages.
背景技术Background technique
随着计算机技术的发展,越来越多的技术(大数据、分布式、区块链Blockchain、人工智能等)应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,但由于金融行业的安全性、实时性要求,也对JSON报文的一致性核对技术提出了更高的要求。With the development of computer technology, more and more technologies (big data, distributed, blockchain, artificial intelligence, etc.) The industry's security and real-time requirements also put forward higher requirements for the consistency check technology of JSON messages.
时下,Json(Java Script Object Notation,JS对象简谱,一种轻量级的数据交换格式,JS全称为Java Script,是一种编程语言)报文在API接口间以及应用前后端的消息传递等场景中都有着非常广泛的应用,尤其对于Java(一门面向对象编程语言)应用开发和数据测试而言,核对接口变动前后的JSON报文是否一致,以及相同数据源的JSON报文在经过多方处理后的返回数据是否一致等,都是属于必须且经常性的操作。Nowadays, Json (Java Script Object Notation, JS object notation, a lightweight data exchange format, JS is called Java Script, which is a programming language) messages are used in scenarios such as API interface and front-end and back-end message transmission. All of them have a very wide range of applications, especially for Java (an object-oriented programming language) application development and data testing, check whether the JSON messages before and after the interface change are consistent, and whether the JSON messages of the same data source are processed by multiple parties Whether the returned data is consistent, etc., are all necessary and frequent operations.
当前常用的JSON报文核对方式是用Beyond Compare(一种文本文件对比工具)等工具或者基于简单的Json开源包来进行数据一致性的比对。然而这些核对方式无法在JSON报文本身数据嵌套层级较深、字段变动或者JSON报文内存在未排序数据列表等情形下,实现数据一致性的核对,导致JSON报文一致性核对效率低下。The currently commonly used JSON message checking method is to use tools such as Beyond Compare (a text file comparison tool) or based on a simple Json open source package to compare data consistency. However, these checking methods cannot implement data consistency checks in situations where the data nesting level of the JSON message itself is deep, fields change, or there is an unsorted data list in the JSON message, resulting in low efficiency of the JSON message consistency check.
发明内容Contents of the invention
本申请的主要目的在于提出一种JSON报文的核对方法和JSON报文的核对装置,旨在解决现有针对JSON报文进行一致性核对的核对效率较低的技术问题。The main purpose of this application is to propose a JSON message checking method and a JSON message checking device, aiming at solving the existing technical problem of low checking efficiency for JSON message consistency checking.
为实现上述目的,本申请提供一种JSON报文的核对方法,所述JSON报文的核对方法包括如下步骤:In order to achieve the above object, the application provides a checking method of a JSON message, and the checking method of the JSON message includes the following steps:
获取待核对JSON报文和预设的报文核对规则,其中,所述报文核对规则基于所述待核对JSON报文进行配置得到;Obtaining the JSON message to be checked and a preset message checking rule, wherein the message checking rule is configured based on the JSON message to be checked;
将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文,并将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文;Converting the first source message in the JSON message to be checked into the second source message of the Map data structure, and converting the first target message in the JSON message to be checked into the first source message of the Map data structure Two target messages;
若比对得到所述第二源报文与所述第二目标报文的MD5值不一致,则按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值;If the comparison shows that the MD5 values of the second source message and the second target message are inconsistent, then determine the source Value value from the second source message according to the message check rule, and according to the Determine the target Value value from the second target message according to the message checking rule;
根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果。Checking is performed according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
此外,为实现上述目的,本申请还提供一种JSON报文的核对装置,所述JSON报文的核对装置包括:In addition, in order to achieve the above object, the present application also provides a JSON message checking device, the JSON message checking device includes:
报文核对准备模块,用于获取待核对JSON报文和预设的报文核对规则,其中,所述报文核对规则基于所述待核对JSON报文进行配置得到;A message check preparation module, configured to obtain a JSON message to be checked and a preset message check rule, wherein the message check rule is configured based on the JSON message to be checked;
报文转换模块,用于将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文,并将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目 标报文;A message conversion module, configured to convert the first source message in the JSON message to be checked into the second source message of the Map data structure, and convert the first target message in the JSON message to be checked Be converted into the second target message of Map data structure;
Value确定模块,用于若比对得到所述第二源报文与所述第二目标报文的MD5值不一致,则按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值;A Value determination module, configured to determine the source Value from the second source message according to the message checking rules if the MD5 values of the second source message and the second target message are inconsistent after comparison value, and determine the target Value value from the second target message according to the message checking rule;
核对模块,用于根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果。A checking module, configured to check according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
其中,本申请JSON报文的核对装置的各个功能模块各自在运行时均实现如上所述的JSON报文的核对方法的步骤。Wherein, each functional module of the device for checking JSON messages in the present application implements the steps of the checking method for JSON messages as described above during operation.
此外,为实现上述目的,本申请还提供一种终端设备,所述终端设备包括:存储器、处理器及存储在所述存储器上并可在所述处理器上运行的JSON报文的核对程序,所述JSON报文的核对程序被所述处理器执行时实现如上所述的JSON报文的核对方法的步骤。In addition, in order to achieve the above object, the present application also provides a terminal device, which includes: a memory, a processor, and a check program for JSON messages stored on the memory and operable on the processor, When the checking program of the JSON message is executed by the processor, the above-mentioned steps of the checking method of the JSON message are realized.
此外,为实现上述目的,本申请还提供一种计算机存储介质,所述计算机存储介质上存储有JSON报文的核对程序,所述JSON报文的核对程序被处理器执行时实现如上所述的JSON报文的核对方法的步骤。In addition, in order to achieve the above purpose, the present application also provides a computer storage medium, the computer storage medium is stored with a check program for JSON messages, and when the check program for JSON messages is executed by a processor, the above-mentioned The steps of the verification method of the JSON message.
此外,为实现上述目的,本申请还提供一种计算机程序产品,所述计算机程序产品包括JSON报文的核对程序,所述JSON报文的核对程序被处理器执行时实现如上所述的JSON报文的核对方法的步骤。In addition, in order to achieve the above purpose, the present application also provides a computer program product, the computer program product includes a check program for JSON messages, and when the check program for JSON messages is executed by a processor, the above-mentioned JSON message is implemented. The steps of the verification method of the document.
本申请通过获取待核对JSON报文和预设的报文核对规则,其中,所述报文核对规则基于所述待核对JSON报文进行配置得到;将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文,并将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文;若比对得到所述第二源报文与所述第二目标报文的MD5值不一致,则按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值;根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果。The present application obtains the JSON message to be checked and the preset message checking rule, wherein, the message checking rule is configured based on the JSON message to be checked; the first in the JSON message to be checked The source message is converted into the second source message of the Map data structure, and the first target message in the JSON message to be checked is converted into the second target message of the Map data structure; The MD5 value of the second source message is inconsistent with the second target message, then determine the source Value value from the second source message according to the message checking rule, and determine the source Value value from the second source message according to the message checking rule Determining a target Value in the second target message; checking according to the source Value and the target Value to obtain a message check result of the unchecked JSON message.
相比于传统采用Beyond Compare工具或者基于简单的Json开源包来进行JSON报文一致性比对的方式,本申请通过将JSON报文转换为Map数据结构,并按照预先配置的报文核对规则基于该Map数据结构确定Value值进行报文一致性核对,如此,能够实现便捷且准确的针对JSON报文的任意字段进行处理及核对,有效地避免了传统方式无法实现核对的情形,提升了JSON报文一致性核对的效率。Compared with the traditional method of using the Beyond Compare tool or based on the simple Json open source package for JSON message consistency comparison, this application converts the JSON message into a Map data structure, and according to the pre-configured message check rules based on The Map data structure determines the Value value to check the consistency of the message. In this way, it can realize convenient and accurate processing and checking of any field of the JSON message, effectively avoiding the situation that the traditional method cannot be checked, and improving the JSON report. The efficiency of document consistency check.
附图说明Description of drawings
图1是本申请实施例方案涉及的硬件运行环境的JSON报文的核对设备结构示意图;Fig. 1 is the schematic structural diagram of the verification device of the JSON message of the hardware operating environment involved in the scheme of the embodiment of the present application;
图2为本申请JSON报文的核对方法一实施例的流程示意图;Fig. 2 is the schematic flow chart of the checking method one embodiment of the JSON message of the present application;
图3为本申请JSON报文的核对方法一实施例所涉及的报文核对规则中的字段说明;Fig. 3 is the description of fields in the message checking rules involved in an embodiment of the checking method of the JSON message of the present application;
图4为本申请JSON报文的核对方法一实施例所涉及的预设核对应用关联的数据表;Fig. 4 is the data table associated with the preset checking application involved in an embodiment of the checking method of the JSON message of the present application;
图5为本申请JSON报文的核对方法一实施例所涉及的应用流程示意图;Fig. 5 is a schematic diagram of the application process involved in an embodiment of the checking method of the JSON message of the present application;
图6为本申请JSON报文的核对装置一实施例的模块示意图。FIG. 6 is a block diagram of an embodiment of a device for checking JSON messages of the present application.
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization, functional features and advantages of the present application will be further described in conjunction with the embodiments and with reference to the accompanying drawings.
具体实施方式detailed description
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。It should be understood that the specific embodiments described here are only used to explain the present application, and are not intended to limit the present application.
如图1所示,图1是本申请实施例方案涉及的硬件运行环境的终端设备结构示意图。As shown in FIG. 1 , FIG. 1 is a schematic structural diagram of a terminal device in a hardware operating environment involved in the solution of the embodiment of the present application.
本申请实施例终端设备为被配置用于针对JSON报文一致性进行核对的终端设备,该终端设备可以是PC、智能手机或服务器设备,其上运行有虚拟机。The terminal device in this embodiment of the present application is a terminal device configured to check the consistency of the JSON message. The terminal device may be a PC, a smart phone, or a server device on which a virtual machine runs.
如图1所示,该终端设备可以包括:处理器1001,例如CPU,网络接口1004,用户接口1003,存储器1005,通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可以是稳定的存储器(non-volatile memory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。As shown in FIG. 1 , the terminal device may include: a processor 1001 , such as a CPU, a network interface 1004 , a user interface 1003 , a memory 1005 , and a communication bus 1002 . Wherein, the communication bus 1002 is used to realize connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. Optionally, the network interface 1004 may include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 can be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001 .
本领域技术人员可以理解,图1中示出的终端设备结构并不构成对设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art can understand that the structure of the terminal device shown in FIG. 1 does not constitute a limitation on the device, and may include more or less components than those shown in the figure, or combine some components, or arrange different components.
如图1所示,作为一种计算机存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及JSON报文的核对程序。As shown in FIG. 1 , the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a checking program for JSON messages.
在图1所示的终端设备中,网络接口1004主要用于连接后台服务器,与后台服务器进行数据通信;用户接口1003主要用于连接客户端(用户端),与客户端进行数据通信;而处理器1001可以用于调用存储器1005中存储的JSON报文的核对程序,并执行下述JSON报文的核对方法中的操作。In the terminal equipment shown in Fig. 1, the network interface 1004 is mainly used to connect the background server and carry out data communication with the background server; the user interface 1003 is mainly used to connect the client (client) and carry out data communication with the client; The device 1001 can be used to call the verification program of the JSON message stored in the memory 1005, and perform the operations in the following JSON message verification method.
基于上述硬件结构,提出本申请JSON报文的核对方法实施例。Based on the above hardware structure, an embodiment of the checking method for the JSON message of the present application is proposed.
需要说明的是,时下,Json(Java Script Object Notation,JS对象简谱,一种轻量级的数据交换格式,JS全称为Java Script,是一种编程语言)报文在API接口间以及应用前后端的消息传递等场景中都有着非常广泛的应用,尤其对于开发和测试而言,核对接口变动前后的JSON报文是否一致,以及相同数据源的JSON报文在经过多方处理后的返回数据是否一致等,都是属于必须且经常性的操作。It should be noted that, nowadays, Json (Java Script Object Notation, JS object notation, a lightweight data exchange format, JS is called Java Script, which is a programming language) messages between the API interface and the front-end and back-end of the application It is widely used in messaging and other scenarios, especially for development and testing, to check whether the JSON messages before and after interface changes are consistent, and whether the returned data of JSON messages from the same data source are consistent after multi-party processing, etc. , are all necessary and frequent operations.
当前常用的JSON报文核对方式是用Beyond Compare(一种文本文件对比工具)等工具或者基于简单的Json开源包来进行数据一致性的比对。然而这些核对方式无法在JSON报文本身数据嵌套层级较深、字段变动或者JSON报文内存在未排序数据列表等情形下,实现数据一致性的核对,导致JSON报文一致性核对效率低下。The currently commonly used JSON message checking method is to use tools such as Beyond Compare (a text file comparison tool) or based on a simple Json open source package to compare data consistency. However, these checking methods cannot implement data consistency checks in situations where the data nesting level of the JSON message itself is deep, fields change, or there is an unsorted data list in the JSON message, resulting in low efficiency of the JSON message consistency check.
针对上述现象,本申请提供一种JSON报文的核对方法,请参照图2,图2为本申请JSON报文的核对方法第一实施例的流程示意图,本申请JSON报文的核对方法应用于如上述的终端设备,本申请JSON报文的核对方法包括:In view of the above phenomenon, this application provides a method for checking JSON messages, please refer to Figure 2, Figure 2 is a schematic flow chart of the first embodiment of the method for checking JSON messages of this application, the method for checking JSON messages of this application is applied to For the above-mentioned terminal device, the checking method of the JSON message in this application includes:
步骤S10,获取待核对JSON报文和预设的报文核对规则,其中,所述报文核对规则基于所述待核对JSON报文进行配置得到;Step S10, obtaining the JSON message to be checked and a preset message checking rule, wherein the message checking rule is configured based on the JSON message to be checked;
需要说明的是,在本实施例中,预设的报文核对规则为预先基于待核对JSON报文进行配置生成,并存储在对应核对规则库当中,用于针对该待核对JSON报文进行一致性核对的规则,该核对规则库具体可以是终端设备在本地存储空间当中维护的MySQL(一个关系型数据库管理系统)或者SQLite(一款轻型的数据库)。It should be noted that, in this embodiment, the preset message checking rules are pre-configured and generated based on the JSON message to be checked, and stored in the corresponding checking rule base, so as to perform consistent Specifically, the checking rule base may be MySQL (a relational database management system) or SQLite (a light database) maintained in the local storage space of the terminal device.
终端设备从存储JSON报文的数据库中获取当前需要进行一致性核对的待核对JSON报文,并从存储报文核对规则的核对规则库当中,获取用于针对该待核对JSON报文进行一致性核对的报文核对规则。The terminal device obtains the JSON message to be checked that currently needs to be checked for consistency from the database storing the JSON message, and obtains the consistency check for the JSON message to be checked from the check rule library that stores message checking rules. Checked packet check rules.
具体地,例如,请参照如图5所示的应用流程,假定存储JSON报文的数据库为终端这边在本地存储空间中独立配置并命名为“JSON报文库”的特定存储空间,该特定存储空间同样可以被维护为MySQL或者SQLite,终端设备将开发、测试甚至运行过程当中产生的JSON报文均编写在该“JSON报文库”当中,从而,终端设备根据接收到针对该“JSON报文库”中某一个接口变动前后分别产生的源报文和目标报文进行一致性核对的请求,即将该源报文和目标报文作为待核对JSON报文,并从该“JSON报文库”中获取该待核对JSON报文准备进行后续的一致性核对。Specifically, for example, please refer to the application process shown in Figure 5, assuming that the database storing JSON messages is a specific storage space independently configured on the terminal side in the local storage space and named "JSON message library". The space can also be maintained as MySQL or SQLite. The terminal device will write the JSON messages generated during development, testing and even operation into the "JSON message library". A request for consistency check of the source message and target message generated before and after a certain interface change, that is, the source message and target message are regarded as the JSON message to be checked, and the JSON message library is obtained from the "JSON message library". The JSON message to be checked is ready for subsequent consistency check.
并且,终端设备在从该“JSON报文库”中获取该待核对JSON报文的同时,还同步的在“核对规则库”当中,获取预先基于该待核对JSON报文进行配置生成,以用于核对该待核对JSON报文中源报文和目标报文是否一致的报文核对规则。Moreover, while the terminal device obtains the JSON message to be checked from the "JSON message library", it also synchronously obtains the pre-configured generation based on the JSON message to be checked in the "checking rule base" for use in Check the message checking rules to check whether the source message and the target message in the JSON message to be checked are consistent.
进一步地,在一种可行的实施例中,本申请JSON报文的核对方法,还可以包括:Further, in a feasible embodiment, the checking method of the JSON message of the present application may also include:
步骤S50,基于所述待核对JSON报文配置生成用于对所述待核对JSON报文进行一致性核对的报文核对规则。Step S50, generating a message checking rule for performing consistency check on the JSON message to be checked based on the configuration of the JSON message to be checked.
终端设备在接收到针对JSON报文进行一致性核对的请求,并确定该请求指向的待核对JSON报文之后,立即基于该待核对JSON报文配置生成用于对该待核对JSON报文进行一致性核对的报文核对规则,并将该报文核对规则进行存储以供调用。After the terminal device receives the request for consistency check on the JSON message and determines the JSON message to be checked pointed to by the request, it immediately generates a consistency check message based on the configuration of the JSON message to be checked. The message check rule of the sex check is used, and the message check rule is stored for calling.
需要说明的是,在本实施例中,终端设备在基于待核对JSON报文配置生成用于对该待核对JSON报文进行一致性核对的报文核对规则之后,即可按照接收到针对JSON报文进行一致性核对的请求的时间,将该报文核对规则存储至核对规则库当中。如此,终端设备在开始针对该待核对JSON报文进行一致性核对时,即可按照请求的时间准确的从核对规则库当中提取出该报文核对规则用于对该待核对JSON报文进行一致性核对。It should be noted that, in this embodiment, after the terminal device generates a message checking rule for consistency checking of the JSON message to be checked based on the configuration of the JSON message to be checked, it can follow the received JSON message The time of the request for the consistency check of the message, and the message check rule is stored in the check rule base. In this way, when the terminal device starts to check the consistency of the JSON message to be checked, it can accurately extract the message checking rule from the checking rule base according to the requested time and use it to perform consistency check on the JSON message to be checked. gender check.
或者,终端设备在配置生成用于对该待核对JSON报文进行一致性核对的报文核对规则之后,还可以直接按照当前时间将该报文核对规则存储至核对规则库当中,从而,终端设备在立即基于请求开始针对该待核对JSON报文进行一致性核对时,终端设备即可按照该当前时间从核对规则库当中提取出最新的报文核对规则用于对该待核对JSON报文进行一致性核对。Alternatively, after the terminal device is configured to generate a message checking rule for consistency checking of the JSON message to be checked, it can also directly store the message checking rule in the checking rule base according to the current time, so that the terminal device When the consistency check for the JSON message to be checked is started immediately based on the request, the terminal device can extract the latest message check rule from the check rule base according to the current time for the consistency check of the JSON message to be checked gender check.
需要说明的是,在本实施例中,由于在该当前时间之后未接收到新的请求,或者还未响应新的请求(终端设备可以被设定为执行完当前请求之后再响应下一个新的请求),从而没有在该当前时间之后配置生成其它的报文核对规则,则当前配置生成的最新的报文核对规则即为用于对该待核对JSON报文进行一致性核对的规则。It should be noted that, in this embodiment, since no new request has been received after the current time, or the new request has not been responded to yet (the terminal device can be set to respond to the next new request after executing the current request Request), so that no other message checking rules are configured and generated after the current time, then the latest message checking rules generated by the current configuration are the rules used to check the consistency of the JSON message to be checked.
进一步地,在一种可行的实施例中,上述步骤S50,基于所述待核对JSON报文配置生成用于对所述待核对JSON报文进行一致性核对的报文核对规则,可以包括:Further, in a feasible embodiment, the above step S50, based on the configuration of the JSON message to be checked, generates a message checking rule for performing consistency check on the JSON message to be checked, which may include:
步骤S501,获取预设的报文核对需求,并解析所述待核对JSON报文的数据结构;Step S501, obtaining a preset message checking requirement, and analyzing the data structure of the JSON message to be checked;
终端设备在确定当前需要进行一致性核对的待核对JSON报文,从而基于该待核对JSON报文配置生成报文核对规则的过程中,先获取针对该待核对JSON报文进行一致性核对的报文核对需求,并同步解析该待核对JSON报文的数据结构。In the process of determining the to-be-checked JSON message that currently needs to be checked for consistency, and thereby generating a message checking rule based on the configuration of the to-be-checked JSON message, the terminal device first obtains the report for the consistency check of the to-be-checked JSON message document verification requirements, and synchronously parse the data structure of the JSON message to be verified.
需要说明的是,在本实施例中,终端设备可以从接收到的针对待核对JSON报文进行一致性核对的请求中,获取进行一致性核对的报文核对需求,该报文核对需求包括但不限于:直接对比字段、对比数组和对比数组内的数组。It should be noted that, in this embodiment, the terminal device can obtain the message checking requirements for consistency checking from the received request for consistency checking on JSON messages to be checked, and the message checking requirements include but Not limited to: comparing fields directly, comparing arrays, and comparing arrays within arrays.
具体地,例如,终端设备在接收到的针对某一个接口变化前后的源报文和目标报文进行一致性比对的请求,并将该源报文和该目标报文一起确定为待核对JSON报文之后,终端设备进一步基于成熟的指令解析技术,从该请求当中确定当前针对该待核对JSON报文进行一致性核对的报文核对需求是直接对比字段、对比数组或者对比数组内的数组,并且,终端设备还基于成熟的数据结构解析技术,解析确定出该源报文和该目标报文各自包含的全部字段等数据结构。Specifically, for example, the terminal device receives a request for consistency comparison between the source message and the target message before and after a certain interface change, and determines the source message and the target message together as the JSON to be checked After the message, the terminal device further determines from the request based on the mature command analysis technology that the current message check requirement for the consistency check of the JSON message to be checked is to directly compare fields, compare arrays, or compare arrays in arrays. Moreover, based on the mature data structure analysis technology, the terminal device analyzes and determines the data structures such as all the fields contained in the source message and the target message respectively.
步骤S502,按照所述报文核对需求配置生成所述数据结构对应的用于对所述待核对JSON报文进行一致性核对的报文核对规则。Step S502, generate a message checking rule corresponding to the data structure according to the message checking requirement configuration and used for checking the consistency of the JSON message to be checked.
终端设备在获取得到针对待核对JSON报文进行一致性核对的报文核对需求,并解析出待核对JSON报文的数据结构之后,即按照该报文核对需求来配置生成与该数据结构相对应从而能够用于准确对该核对JSON报文进行一致性核对的报文核对规则。After the terminal device obtains the message verification requirement for the consistency check of the JSON message to be checked, and parses out the data structure of the JSON message to be checked, it configures and generates the corresponding data structure according to the message checking requirement. Therefore, it can be used as a message checking rule for accurately checking the consistency of the checking JSON message.
具体地,例如,请参照如图3所示的报文核对规则中的字段说明,假定终端设备从对待核对JSON报文进行一致性核对的请求中,获取得到的报文核对需求是:针对源报文和 目标报文直接进行字段的比对,从而确定所需配置生成的报文核对规则中,from_path=source.a.b?、to_path=target.x.y,且,终端设备解析得到该源报文和目标报文各自包含的全部字段之后,即可配置生成与该全部字段相对应从而能够用于准确核对该源报文和该目标报文一致性的报文核对规则为:INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark)VALUES('T3_ACCT_INFO_NEW_02','T3_ACCT_INFO_NEW','VALUE','custNumber','CUST_NUMBER','N','N',”,”,'比较T3accountInfos外部内容')。Specifically, for example, please refer to the field descriptions in the message checking rules shown in Figure 3, assuming that the terminal device obtains the message checking requirements from the request for consistency checking of JSON messages to be checked: The message and the target message are directly compared with each other to determine the required configuration. In the generated message check rule, from_path=source.a.b? , to_path=target.x.y, and after the terminal device parses and obtains all the fields contained in the source message and the target message, it can be configured to generate corresponding to all the fields so that it can be used to accurately check the source message and the target message The message check rule for target message consistency is: INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark)VALUES('T3_ACCT_INFO_NEW_ALUE02','FO3_UEW_IN' 'custNumber','CUST_NUMBER','N','N',",",",'Compare T3accountInfos external content').
或者,假定终端设备从对待核对JSON报文进行一致性核对的请求中,获取得到的报文核对需求是:针对源报文和目标报文进行数组的比对,从而确定所需配置生成的报文核对规则中,需要配置数组的名称,而数组里不希望对比的字段可配置在“sys_rmb_compare_def.ignore_field_from”和“sys_rmb_compare_def.ignore_fieldto”,且,终端设备解析得到该源报文和目标报文各自包含的全部字段之后,即可配置生成与该全部字段相对应从而能够用于准确核对该源报文和该目标报文一致性的报文核对规则为:INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark)VALUES('T3_TRANS_NEW_01','T3_TRANS_NEW','LIST','output.TXN_ARRAY','TXN_ARRAY','N','N',”,”,'比较T3 accountInfos')。Or, assume that the terminal device obtains the message verification requirement from the request for consistency check of the JSON message to be checked: compare the arrays of the source message and the target message, so as to determine the message generated by the required configuration. In the text check rule, the name of the array needs to be configured, and the fields that do not want to be compared in the array can be configured in "sys_rmb_compare_def.ignore_field_from" and "sys_rmb_compare_def.ignore_fieldto", and the terminal device parses and obtains that the source message and the target message respectively contain After all the fields, you can configure and generate a packet check rule that corresponds to all the fields and can be used to accurately check the consistency between the source packet and the target packet: INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path ,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark)VALUES('T3_TRANS_NEW_01','T3_TRANS_NEW','LIST','output.TXN_ARRAY','TXN_ARRAY','N','N',",",' Compare T3 accountInfos').
再或者,假定终端设备从对待核对JSON报文进行一致性核对的请求中,获取得到的报文核对需求是:针对源报文和目标报文进行数组内数组的比对,从而确定所需配置生成的报文核对规则中,需要使用到“#”分割不同嵌套层级的数组,且,终端设备解析得到该源报文和目标报文各自包含的全部字段之后,即可配置生成与该全部字段相对应从而能够用于准确核对该源报文和该目标报文一致性的报文核对规则为:INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark)VALUES('T3_ACCT_INFO_NEW_03','T3_ACCT_INFO_NEW','LIST_LIST','accountInfos#subAccountInfo','ACCOUNT_INFOS#SUB_ACCOUNT_INFO','N','N',Alternatively, assume that the terminal device obtains the message verification requirement from the request for consistency check of the JSON message to be checked: compare the array within the array for the source message and the target message, so as to determine the required configuration In the generated message checking rules, "#" needs to be used to separate the arrays of different nesting levels, and after the terminal device parses and obtains all the fields contained in the source message and the target message, it can be configured to generate and match all the fields. The message check rule that corresponds to the field and can be used to accurately check the consistency between the source message and the target message is: INSERT INTO sys_checkrule_def(id,group_id,compare_type,from_path,to_path,check_first_only_if_list,check_size_if_list,from_check_fields,to_check_fields,remark )VALUES('T3_ACCT_INFO_NEW_03','T3_ACCT_INFO_NEW','LIST_LIST','accountInfos#subAccountInfo','ACCOUNT_INFOS#SUB_ACCOUNT_INFO','N','N',
'accountBalance,accountStatus,acctNo,availableBalance,currencyCode,openChannelId,openDate,productId,subAccountSerialNo','ACCOUNT_BALANCE,ACCOUNT_STATUS,ACCT_NO,AVAILABLE_BALANCE,CURRENCY_CODE,OPEN_CHANNEL_ID,OPEN_DATE,PRODUCT_ID,SUB_ACCOUNT_SERIAL_NO','比较T3 subAccountInfo')。'accountBalance,accountStatus,acctNo,availableBalance,currencyCode,openChannelId,openDate,productId,subAccountSerialNo','ACCOUNT_BALANCE,ACCOUNT_STATUS,ACCT_NO,AVAILABLE_BALANCE,CURRENCY_CODE,OPEN_CHANNEL_ID,OPEN_DATE,PRODUCT_ID,SUB_ACCOUNT_SERIAL_NO','比较T3 subAccountInfo')。
在本实施例中,通过获取针对待核对JSON报文进行一致性核对的报文核对需求,并同步解析该待核对JSON报文的数据结构,从而按照该报文核对需求来配置生成与该数据结构相对应从而能够用于准确对该核对JSON报文进行一致性核对的报文核对规则。如此,相比于传统采用Beyond Compare工具或者基于简单的Json开源包来进行JSON报文一致性比对的方式,本申请不需要额外开发工作,仅通过按照报文核对需求来动态配置对应的报文核对规则,即可实现复杂的、可定制化的以及多层级的JSON报文的一致性核对,进一步提高了核对效率。In this embodiment, the data structure of the JSON message to be checked is synchronously analyzed by obtaining the message checking requirement for the consistency check of the JSON message to be checked, thereby configuring and generating the data according to the message checking requirement. The structure corresponds to the message checking rule that can be used to accurately check the consistency of the checked JSON message. In this way, compared to the traditional way of using the Beyond Compare tool or based on the simple Json open source package for JSON message consistency comparison, this application does not require additional development work, and only dynamically configures the corresponding message according to the message verification requirements. By using the text checking rules, the consistency checking of complex, customizable and multi-level JSON messages can be realized, which further improves the checking efficiency.
步骤S20,将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文,并将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文;Step S20, converting the first source message in the JSON message to be checked into the second source message of the Map data structure, and converting the first target message in the JSON message to be checked into Map data the second target message of the structure;
终端设备在获取当前需要进行一致性核对的待核对JSON报文之后,即进一步将该待核对JSON报文当中的第一源报文,转换为Map数据结构的第二源报文,并且,还将该待核对JSON报文当中的第一目标报文,也转换为Map数据结构的第二目标报文。After obtaining the to-be-checked JSON message that needs to be checked for consistency, the terminal device further converts the first source message in the to-be-checked JSON message into the second source message of the Map data structure, and also The first target message in the to-be-checked JSON message is also converted into the second target message of the Map data structure.
具体地,例如,终端设备在根据接收到针对“JSON报文库”中某一个接口变动前后分别产生的源报文和目标报文进行一致性核对的请求,从而将该源报文和目标报文作为待核对JSON报文,并从该“JSON报文库”中获取到该待核对JSON报文以准备进行一致性核对之后,终端设备即将该源报文作为第一源报文,以将该第一源报文转换为Map数据结构的 第二源报文,并且,终端设备还将该目标报文作为第一目标报文,以将该第一目标报文转换为Map数据结构的第二目标报文,以供后续按照该Map数据结构的第二源报文和第二目标报文便捷的确定Value值进行比对。Specifically, for example, the terminal device receives a request for consistency check of the source message and the target message generated before and after a certain interface change in the "JSON message library", so that the source message and the target message As the JSON message to be checked, and after obtaining the JSON message to be checked from the "JSON message library" to prepare for the consistency check, the terminal device will use the source message as the first source message to use the second A source message is converted into a second source message of the Map data structure, and the terminal device also uses the target message as the first target message to convert the first target message into the second target of the Map data structure message, so that the value value can be conveniently determined and compared with the second source message and the second target message according to the Map data structure.
进一步地,在一种可行的实施例中,所述Map数据结构包括:普通型Map数据结构和嵌套型Map数据结构,步骤S20中,“将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文”的步骤,可以包括:Further, in a feasible embodiment, the Map data structure includes: an ordinary Map data structure and a nested Map data structure, in step S20, "the first source in the JSON message to be checked The step of converting the message into the "second source message of the Map data structure" may include:
步骤S201,在所述第一源报文中确定普通形式的第一报文数据和/或者嵌套形式的第二报文数据;Step S201, determining the first message data in common form and/or the second message data in nested form in the first source message;
终端设备在将待核对JSON报文中的第一源报文转换成为Map数据结构的第二源报文时,先在该第一源报文确定出普通形式的第一报文数据和/或者嵌套形式的第二报文数据。When the terminal device converts the first source message in the JSON message to be checked into the second source message of the Map data structure, it first determines the first message data and/or The second packet data in nested form.
需要说明的是,在本实施例中,普通形式的第一报文数据即为JSON报文当中K-V形式的报文内容,而嵌套形式的第二报文数据即为JSON报文当中K-List形式或者K-List(List)形式的报文内容。It should be noted that, in this embodiment, the first message data in common form is the message content in the form of K-V in the JSON message, and the second message data in the nested form is the K-V form in the JSON message. Message content in the form of List or K-List (List).
步骤S202,将所述第一报文数据转换为所述普通型Map数据结构的第二源报文,和/或者,将所述第二报文数据转换为所述嵌套型Map数据结构的第二源报文;Step S202, converting the first message data into the second source message of the common Map data structure, and/or converting the second message data into the nested Map data structure second source message;
终端设备在第一源报文确定出普通形式的第一报文数据和/或者嵌套形式的第二报文数据之后,即分别针对该第一报文数据和/或者第二报文数据进行转换,即,将该第一报文数据直接转换成为普通型Map数据结构的第二源报文,和/或者,将该第二报文数据对应转换为嵌套型Map数据结构的第二源报文。After the first source message determines the first message data in common form and/or the second message data in nested form, the terminal device respectively performs Converting, that is, directly converting the first message data into a second source message of a common Map data structure, and/or correspondingly converting the second message data into a second source of a nested Map data structure message.
需要说明的是,在本实施例中,普通型Map数据结构为WeMap(K,V),该WeMap(K,V)的报文可以直接基于取值算法WeMap.get(K)获取得到对应的Value值;而嵌套型Map数据结构则为WeMap(K,List(WeMap((K1,V1),(K2,V2),……))),该WeMap(K,List(WeMap((K1,V1),(K2,V2),……)))的报文则需要对应嵌套层级的取值算法来获取对应嵌套层级的Value值,即,通过WeMap.get(K.K1)获取对应的V1,WeMap.get(K.K2)获取对应的V2,通过WeMap.get(K)可以获取到List(WeMap((K1,V1),(K2,V2),……)),其中,V1、V2分别指对应第1层级的Value值和对应第2层级的Value值。依此类推,可支持任意多层级JSON报文中对应Value值的提取。It should be noted that, in this embodiment, the common Map data structure is WeMap(K, V), and the message of the WeMap(K, V) can be obtained directly based on the value algorithm WeMap.get(K) to obtain the corresponding Value; while the nested Map data structure is WeMap(K,List(WeMap((K1,V1),(K2,V2),……))), the WeMap(K,List(WeMap((K1, V1), (K2, V2),...))) messages need the value algorithm corresponding to the nesting level to obtain the Value value of the corresponding nesting level, that is, get the corresponding value through WeMap.get(K.K1) V1, WeMap.get(K.K2) obtains the corresponding V2, and the List(WeMap((K1,V1),(K2,V2),…)) can be obtained through WeMap.get(K), where V1 , V2 respectively refer to the Value corresponding to the first level and the Value corresponding to the second level. By analogy, it can support the extraction of the corresponding Value value in any multi-level JSON message.
进一步地,在一种可行的实施例中,上述步骤S20中,“将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文”的步骤,Further, in a feasible embodiment, in the above step S20, the step of "converting the first target message in the JSON message to be checked into the second target message of the Map data structure",
步骤S203,在所述第一目标报文中确定普通形式的第三报文数据和/或者嵌套形式的第四报文数据;Step S203, determining the third message data in common form and/or the fourth message data in nested form in the first target message;
终端设备在将待核对JSON报文中的第一目标报文转换成为Map数据结构的第二目标报文时,先在该第一目标报文中确定出普通形式的第三报文数据和/或者嵌套形式的第四报文数据。When the terminal device converts the first target message in the JSON message to be checked into the second target message of the Map data structure, it first determines the third message data in a common form in the first target message and/or Or the fourth message data in a nested form.
步骤S204,将所述第三报文数据转换为所述普通型Map数据结构的第二目标报文,和/或者,将所述第四报文数据转换为所述嵌套型Map数据结构的第二目标报文。Step S204, converting the third message data into the second target message of the common Map data structure, and/or converting the fourth message data into the nested Map data structure Second target message.
终端设备在第一目标报文确定出普通形式的第三报文数据和/或者嵌套形式的第四报文数据之后,即分别针对该第三报文数据和/或者第四报文数据进行转换,即,将该第三报文数据直接转换成为普通型Map数据结构的第二目标报文,和/或者,将该第四报文数据对应转换为嵌套型Map数据结构的第二目标报文。After the terminal device determines the third message data in common form and/or the fourth message data in nested form in the first target message, it respectively performs Converting, that is, directly converting the third message data into a second target message of a common Map data structure, and/or correspondingly converting the fourth message data into a second target of a nested Map data structure message.
进一步地,在一种可行的实施例中,步骤S204中,“将所述第四报文数据转换为所述嵌套型Map数据结构的第二目标报文”的步骤,可以包括:Further, in a feasible embodiment, in step S204, the step of "converting the fourth message data into the second target message of the nested Map data structure" may include:
步骤S2041,循环检测所述第四报文数据的各嵌套层级中健值对应的Value值类型,其中,所述Value值类型包括:普通Value值、JSON数组和JSON对象;Step S2041, cyclically detect the Value value type corresponding to the key value in each nesting level of the fourth message data, wherein the Value value type includes: ordinary Value value, JSON array and JSON object;
需要说明的,在本实施例中,终端设备在将待核对JSON报文中,嵌套形式的报文数 据转换成为嵌套型Map数据结构的报文时,针对每一个层级循环执行获取Key值、获取Key对应的Value值和判断Value值的类型的操作。It should be noted that, in this embodiment, when the terminal device converts the message data in the nested form in the JSON message to be checked into a message of the nested Map data structure, it loops for each level to obtain the Key value , Obtain the Value value corresponding to the Key and determine the type of the Value value.
终端设备在将嵌套形式的第四报文数据转换为嵌套型Map数据结构的第二目标报文的过程中,针对该第四报文数据的每一个嵌套层级,均执行先获取Key值、再获取Key对应的Value值,和判断Value值的类型是否为普通Value值、JSON数组和JSON对象。In the process of converting the fourth message data in the nested form into the second target message of the nested Map data structure, the terminal device performs, for each nesting level of the fourth message data, first obtaining the Key value, and then obtain the Value value corresponding to the Key, and determine whether the type of the Value value is a normal Value value, JSON array, or JSON object.
步骤S2042,若检测到所述Value值类型为所述普通Value值,则将所述键值记录为Map数据结构以得到所述第二目标报文。Step S2042, if it is detected that the type of the Value is the normal Value, record the key value as a Map data structure to obtain the second target message.
终端设备在针对嵌套形式的第四报文数据的每一个嵌套层级,判断Value值的类型的过程中,若判断到Value值的类型为普通Value值,则终端设备直接将该嵌套层级的键值直接记录为Map数据结构,如此,在全部嵌套层级的键值均被记录为Map数据结构之后,即完成了将第四报文数据转换成为嵌套型Map数据结构的第二目标报文。In the process of judging the type of the Value value for each nesting level of the fourth message data in the nested form, if the terminal device determines that the type of the Value value is a normal Value value, the terminal device directly sets the value of the nesting level The key value of the key is directly recorded as a Map data structure. In this way, after the key values of all nested levels are recorded as a Map data structure, the second goal of converting the fourth message data into a nested Map data structure is completed. message.
具体地,例如,终端设备针对待核对JSON报文中的每一个嵌套层级循环执行:获取Key值、获取Key对应的Value值以及判断Value值的类型的操作,并在判断到该Value值的类型为JSON数组(Array)时,进一步将该Value值作为“List类型”以进入下一层级的循环处理,且在Map数据中写入值:(Key,toList(Value));而在判断到该Value值的类型为JSON对象(Object)时,进一步将该Value值作为“Json对象”处理,并在Map数据中写入值:(Key,toWeMap(Value)),如此,在后续处理中调用该“toWeMap”后,即可重新返回“获取Key值”的步骤以实现对该Value值的递归解析;最后,若判断到该Value值的类型为普通Value值,则类型为普通的值时,终端设备即可直接将该Value值直接写入到Map数据,即在Map数据写入值:Map(Key,Value),如此,即完成将该待核对JSON报文转换成为Map数据结构。Specifically, for example, for each nested level in the JSON message to be checked, the terminal device loops through the operations of obtaining the Key value, obtaining the Value value corresponding to the Key, and judging the type of the Value value. When the type is a JSON array (Array), further use the Value value as a "List type" to enter the next level of loop processing, and write the value in the Map data: (Key,toList(Value)); When the type of the Value value is a JSON object (Object), further treat the Value value as a "Json object", and write the value in the Map data: (Key, toWeMap(Value)), so that it is called in subsequent processing After the "toWeMap", you can return to the step of "obtaining the Key value" to realize the recursive analysis of the Value value; finally, if it is judged that the type of the Value value is an ordinary Value value, then when the type is an ordinary value, The terminal device can directly write the Value value into the Map data, that is, write the value in the Map data: Map(Key, Value), so that the conversion of the JSON message to be checked into a Map data structure is completed.
需要说明的是,在本实施例中,toList的功能是实现对于List类型的值,解析内部的所有Key-Value,并保存到Map数据结构中。It should be noted that, in this embodiment, the function of toList is to parse all the Key-Values in the List type and store them in the Map data structure.
终端设备在判断到Value值的类型为JSON数组(Array),从而进一步将该Value值作为“List类型”以进入下一层级的循环处理,且在Map数据中写入值:(Key,toList(Value))之后,进一步调用该“toList”以开始针对List中的每一个值再循环执行作:获取Value值和判断Value值的类型的操作,并且,同样的,终端设备在判断Value值的类型时,若判断到该Value值的类型为Json数组,则继续针对该Value值作为“List类型”以进入下一层级的循环处理,而List写入值:(toList(Value)),如此,可递归调用“toList”以对List内部的值进行递归处理;而在判断到Value值的类型为Json对象时,将该Value至作为Json对象处理,List写入值:(toWeMap(Value)),从而,可进一步调用“toWeMap”,实现对Value值的递归解析将JSON报文中全部的Value值转换为Map数据结构中的值;最后,在判断到Value值的类型为普通的值时,即直接将该Value值写入List(Value)。After the terminal device judges that the type of the Value value is a JSON array (Array), it further uses the Value value as a "List type" to enter the next level of loop processing, and writes the value in the Map data: (Key,toList( Value)), further call the "toList" to start recirculation execution for each value in the List: the operation of obtaining the Value value and judging the type of the Value value, and, similarly, the terminal device is judging the type of the Value value , if it is judged that the type of the Value value is a Json array, then continue to use the Value value as a "List type" to enter the next level of loop processing, and the List writes the value: (toList(Value)), so, you can Recursively call "toList" to recursively process the value inside the List; and when it is judged that the type of the Value value is a Json object, the Value is treated as a Json object, and the value is written into the List: (toWeMap(Value)), so that , you can further call "toWeMap" to implement recursive parsing of the Value value and convert all the Value values in the JSON message into values in the Map data structure; finally, when it is judged that the type of the Value value is an ordinary value, that is, directly Write the Value value to List(Value).
此外,终端设备将嵌套形式的第二报文数据转换为嵌套型Map数据结构的第二源报文的过程,与上述将嵌套形式的第四报文数据转换为嵌套型Map数据结构的第二目标报文的过程相同,在此不再进行赘述。In addition, the process that the terminal device converts the second message data in the nested form into the second source message of the nested Map data structure is the same as converting the fourth message data in the nested form into the nested Map data. The process of the second target packet of the structure is the same, and will not be repeated here.
步骤S30,若比对得到所述第二源报文与所述第二目标报文的MD5值不一致,则按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值;Step S30, if the MD5 values of the second source message and the second target message are inconsistent according to the comparison, then determine the source Value value from the second source message according to the message checking rule, and determining a target Value from the second target message according to the message checking rule;
终端设备在将待核对JSON报文当中的第一源报文和第一目标报文,均转换为Map数据结构的第二源报文和第二目标报文,之后,先针对该第二源报文和第二目标报文进行全文整体的MD5值比对,从而在比对到该第二源报文和该第二目标报文各自的MD5值不相同时,再进一步按照已经获取得到用于针对该待核对JSON报文进行一致性核对的报文核对规则,在该第二源报文确定源Value值,和在该第二目标报文当中确定目标Value值 以供后续进行核对。The terminal device converts the first source message and the first target message in the JSON message to be checked into the second source message and the second target message of the Map data structure, and then first targets the second source message The message and the second target message are compared with the MD5 value of the whole text, so that when the MD5 values of the second source message and the second target message are not the same, further according to the acquired Based on the message checking rule for consistency checking of the JSON message to be checked, the source Value is determined in the second source message, and the target Value is determined in the second target message for subsequent checking.
需要说明的是,在本实施例中,若终端设备针对该第二源报文和第二目标报文进行全文整体的MD5值比对,并在比对到该第二源报文和该第二目标报文各自的MD5值相同时,终端设备即可直接得到待核对JSON报文中,源报文和目标报文的一致性核对成功的报文核对结果。It should be noted that, in this embodiment, if the terminal device compares the MD5 value of the whole text of the second source message and the second target message, and compares the second source message and the second target message When the MD5 values of the two target messages are the same, the terminal device can directly obtain the message checking result of the successful consistency check between the source message and the target message in the JSON message to be checked.
步骤S40,根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果。Step S40, check according to the source Value and the target Value to obtain a message check result of the JSON message to be checked.
终端设备在第二源报文中确定出源Value值,和在第二目标报文当中确定出目标Value值之后,即通过比对该源Value值和该目标Value值是否相同,并在确定相同时,对应的得到该待核对JSON报文中,源报文和目标报文的一致性核对成功的报文核对结果,否则,在确定不相同时,对应的得到该待核对JSON报文中,源报文和目标报文的一致性核对失败的报文核对结果。After determining the source value in the second source message and determining the target value in the second target message, the terminal device compares whether the source value and the target value are the same, and determines the corresponding Simultaneously, in the JSON message to be checked, the message checking result of the consistency check of the source message and the target message is obtained correspondingly; otherwise, when it is determined that they are different, correspondingly, in the JSON message to be checked, The check result of the message that the consistency check between the source message and the target message fails.
具体地,例如,请参照如图5所示应用流程中,终端设备通过核对应用(图示核对APP)针对待核对JSON报文进行一致性核对的实例中的步骤2,若终端设备通过核对应用在确定报文核对类型为Value类型,从而直接按照该Value类型在报文核对规则中对应的取值路径,从第二源报文和第二目标报文中确定出相同Key各自对应的源Value值和目标Value值,之后,终端设备即比对该源Value值和该目标Value值是否相同,并,如果在比对到该源Value值和该目标Value值相同时,得到当前按照报文核对规则针对该待核对JSON报文进行一致性核对的报文核对结果为成功,相反的,如果对到该源Value值和该目标Value值不相同,则得到报文核对结果为失败,并记录失败的原因。Specifically, for example, please refer to step 2 in the example of the terminal device performing a consistency check on the JSON message to be checked through the verification application (the verification APP shown in the figure) in the application process shown in Figure 5. If the terminal device passes the verification application After determining that the message check type is the Value type, the source Value corresponding to the same Key is determined from the second source message and the second target message directly according to the value path corresponding to the Value type in the message check rule value and the target Value value, after that, the terminal device compares whether the source Value value is the same as the target Value value, and if the source Value value is the same as the target Value value, it obtains the current verification according to the message The rule checks the consistency of the JSON message to be checked, and the message check result is successful. On the contrary, if the source value and the target value are not the same, the message check result is failed, and the failure is recorded s reason.
进一步地,在一种可行的实施例中,所述源Value值包括:内层源Value值,所述目标Value值包括:内层目标Value值,上述步骤S30,可以包括:Further, in a feasible embodiment, the source value includes: an inner source value, and the target value includes: an inner target value. The above step S30 may include:
步骤S301,确定预设的Value报文核对类型在所述报文核对规则中对应的第一取值路径;Step S301, determining the first value path corresponding to the preset Value message check type in the message check rule;
需要说明的是,在本实施例中,终端设备具体可以通过解析所接收到的针对待核对JSON报文进行一致性核对的请求,来获取得到该预设的Value报文核对类型。It should be noted that, in this embodiment, the terminal device may specifically acquire the preset Value message check type by parsing the received request for consistency check on the JSON message to be checked.
终端设备在按照获取得到报文核对规则,分别从第二源报文和第二目标报文中确定源Value值和目标Value值时,若获取到针对待核对JSON报文进行一致性核对的Value报文核对类型,则按照该Value报文核对类型在该第二源报文和该第二目标报文中,确定与该Value类型相对应以用于提取内层源Value值和内层目标Value值的第一取值路径。When the terminal device determines the source value and the target value from the second source message and the second target message respectively according to the obtained message check rule, if the value obtained for the consistency check of the JSON message to be checked is Message check type, then according to the Value message check type in the second source message and the second target message, it is determined to be corresponding to the Value type for extracting the inner layer source Value value and the inner layer target Value The first value path for the value.
步骤S302,按照所述第一取值路径从所述第二源报文中确定所述内层源Value值,和按照所述取值路径从所述第二目标报文中确定所述内层目标Value值。Step S302, determining the inner source Value value from the second source message according to the first value path, and determining the inner layer value from the second target message according to the value path Target Value.
终端设备在按照Value报文核对类型从报文核对规则当中确定出第一取值路径之后,即进一步按照该第一取值路径在多层级的第二源报文当中获取得到最里层的内层源Value值,以及,同样按照该第一取值路径在多层级的第二目标报文中获取得到最里层的内层目标Value值。After the terminal device determines the first value path from the message verification rules according to the type of the Value message verification, it further obtains the innermost content in the multi-level second source message according to the first value path. The layer source Value value, and also obtain the innermost layer target Value value in the multi-level second target message according to the first value acquisition path.
具体地,例如,假定终端设备针对待核对JSON报文中的第一源报文进行转换得到的Map数据结构的第二源报文为:WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),……)))))。如此,若终端设备获取得到Value报文核对类型,并以该Value报文核对类型从报文核对规则当中确定出的第一取值路径为:Key为K.K1.K2,则终端设备即直接按照该Key为K.K1.K2从第二源报文:WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),……)))))中,获取到最内层的V2作为内层源Value值。同理,终端设备可从第二目标报文获取到最里层的内层目标Value值。Specifically, for example, it is assumed that the second source message of the Map data structure obtained by converting the first source message in the JSON message to be checked by the terminal device is: WeMap(K,List(WeMap(K1,List(WeMap( (K2,V2),(K3,V3),...))))). In this way, if the terminal device obtains the Value message check type, and uses the Value message check type to determine the first value path from the message check rules: Key is K.K1.K2, then the terminal device directly According to the Key is K.K1.K2 from the second source message: WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),...))))) , get the innermost V2 as the inner source Value. Similarly, the terminal device may obtain the innermost inner target Value from the second target packet.
进一步地,步骤S40,可以包括:Further, step S40 may include:
步骤S401,将所述内层源Value值与所述内层目标Value值进行比对得到比对结果;Step S401, comparing the inner source Value with the inner target Value to obtain a comparison result;
步骤S402,若所述比对结果为所述内层源Value值和所述内层目标Value值相同,则得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。Step S402, if the comparison result is that the inner source Value and the inner target Value are the same, then obtain a message check result indicating that the consistency check of the to-be-checked JSON message is successful.
具体地,例如,终端设备按照第一取值路径:Key为K.K1.K2,从第二源报文:WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),……)))))中,获取到最内层的V2作为内层源Value值,以及,按照该第一取值路径:Key为K.K1.K2,从与该第二源报文具有相同Map数据结构的第二目标报文获取到最里层的内层目标Value值,之后,终端设备即比对该内层源Value值和该内层目标Value值是否相同,并,在比对到该内层源Value值和该内层目标Value值相同时,得到当前按照报文核对规则针对该待核对JSON报文进行一致性核对的报文核对结果为成功,相反的,如果对到该源Value值和该目标Value值不相同,则得到报文核对结果为失败,并记录失败的原因。Specifically, for example, the terminal device follows the first value path: Key is K.K1.K2, and from the second source message: WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),( In K3,V3),...))))), the innermost V2 is obtained as the inner source Value value, and, according to the first value path: Key is K.K1.K2, from the The second target message with the same Map data structure in the second source message obtains the innermost inner target Value value, and then the terminal device compares whether the inner source Value value is the same as the inner target Value value, And, when comparing the source value of the inner layer with the target value of the inner layer, it is obtained that the message checking result of the consistency checking of the JSON message to be checked according to the message checking rule is successful, and the opposite , if the source value is not the same as the target value, the message check result is failed, and the reason for the failure is recorded.
进一步地,在另一种可行的实施例中,所述源Value值包括:第一源字段Value值,所述目标Value值包括:第一目标字段Value值,上述步骤S30,还可以包括:Further, in another feasible embodiment, the source Value includes: a first source field Value, and the target Value includes: a first target field Value, the above step S30 may also include:
步骤S303,确定预设的List报文核对类型在所述报文核对规则中对应的第二取值路径;Step S303, determining the second value path corresponding to the preset List message check type in the message check rule;
需要说明的是,在本实施例中,终端设备具体可以通过解析所接收到的针对待核对JSON报文进行一致性核对的请求,来获取得到该预设的List报文核对类型。It should be noted that, in this embodiment, the terminal device may specifically obtain the preset List message check type by parsing the received request for consistency check on the JSON message to be checked.
终端设备在按照获取得到报文核对规则,分别从第二源报文和第二目标报文中确定源Value值和目标Value值时,若获取到针对待核对JSON报文进行一致性核对的List报文核对类型,则按照该List报文核对类型在该第二源报文和该第二目标报文中,确定与该List类型相对应以用于提取第一源字段Value值和第一目标字段Value值的第二取值路径。When the terminal device determines the source value and the target value from the second source message and the second target message respectively according to the obtained message checking rules, if it obtains the List for consistency check for the JSON message to be checked Message check type, then according to the List message check type in the second source message and the second target message, determine that it is corresponding to the List type for extracting the first source field Value value and the first target The second path to obtain the value of the field Value.
步骤S304,按照所述第二取值路径从所述第二源报文的各条源报文数据中确定所述第一源字段Value值,和按照所述第二取值路径从所述第二目标报文的各条源报文数据中确定所述第一目标字段Value值。Step S304: Determine the value of the first source field Value from each piece of source message data in the second source message according to the second value path, and determine the value of the first source field Value from the first value path according to the second value path. The value of the first target field Value is determined in each piece of source message data of the second target message.
终端设备在按照List报文核对类型从报文核对规则当中确定出第二取值路径之后,即进一步按照该第二取值路径在多层级的第二源报文的各条源报文数据当中,获取得到每一层级源报文数据的第一源字段Value值,以及,同样按照该第二取值路径在多层级的第二目标报文的各条源报文数据当中,获取得到每一层级源报文数据的第一目标字段Value值。After the terminal device determines the second value path from the message verification rules according to the type of the List message check, it further selects among the source message data of the multi-level second source message according to the second value path. , to obtain the first source field Value value of each level of source message data, and, also according to the second value path, among the source message data of the multi-level second target message, to obtain each Value of the first target field of hierarchical source packet data.
具体地,例如,假定终端设备针对待核对JSON报文中的第一源报文进行转换得到的Map数据结构的第二源报文为K,List形式的WeMap(K,List(WeMap((K1,V1),(K2,V2),……)))。如此,若终端设备获取得到Value报文核对类型,并以该List报文核对类型从报文核对规则当中确定出的第二取值路径为:Key为K,则终端设备即直接按照该Key为K从第二源报文:WeMap(K,List(WeMap((K1,V1),(K2,V2),……)))中,获取到最外层List对应的源报文数据的第一源字段Value值为:List(WeMap((K1,V1),(K2,V2),……)),如此类推得到全部每一层级List对应的源报文数据的第一源字段Value值。同理,终端设备可从第二目标报文的各条源报文数据当中,获取得到每一层级源报文数据的第一目标字段Value值。Specifically, for example, it is assumed that the second source message of the Map data structure obtained by the terminal device by converting the first source message in the JSON message to be checked is WeMap(K, List(WeMap((K1 ,V1),(K2,V2),...))). In this way, if the terminal device obtains the Value message check type, and uses the List message check type to determine the second value path from the message check rules: Key is K, then the terminal device directly follows the Key as K obtains the first source message data corresponding to the outermost List from the second source message: WeMap(K,List(WeMap((K1,V1),(K2,V2),...))) The source field Value value is: List(WeMap((K1,V1),(K2,V2),...)), and so on to obtain the first source field Value value of all the source message data corresponding to each level of List. Similarly, the terminal device may obtain the Value of the first target field of each level of source message data from each piece of source message data in the second target message.
进一步地,步骤S40,还可以包括:Further, step S40 may also include:
步骤S403,按照所述List类型在所述报文核对规则中对应的排序方式,对各所述源报文数据和各所述目标报文数据进行排序;Step S403, sorting each of the source message data and each of the target message data according to the sorting manner corresponding to the List type in the message checking rule;
需要说明的是,在本实施例中,终端设备可基于接收到的针对待核对JSON报文进行一致性核对的请求,在报文核对规则当中配置排序字段。It should be noted that, in this embodiment, the terminal device may configure a sorting field in the message checking rule based on the received request for consistency checking on the JSON message to be checked.
具体地,例如,终端设备在获取到第二源报文每一层List对应的源报文数据的第一源字段Value值,以及从第二目标报文每一层List对应的目标报文数据的第一目标字段Value值之后,终端设备先按照报文核对规则中配置的排序字段,分别对该每一层级List中的 多条报文数据进行排序得到排序后的报文数据。Specifically, for example, after the terminal device obtains the first source field Value value of the source message data corresponding to each layer List of the second source message, and the target message data corresponding to each layer List of the second target message After the value of the first target field Value, the terminal device first sorts the multiple pieces of message data in the List of each level according to the sorting field configured in the message checking rule to obtain the sorted message data.
步骤S404,核对经过排序后的各所述源报文数据和各所述目标报文数据各自的第一数据条数是否一致;Step S404, checking whether the number of the first data pieces of each of the sorted source message data and each of the target message data is consistent;
终端设备在各条源报文数据和各条各目标报文数据进行排序之后,按照报文核对规则对该排序之后各条源报文数据和各条目标报文数据各自的第一数据条数是否一致。After the terminal device sorts each piece of source message data and each piece of target message data, the first data number of each piece of source message data and each piece of target message data after the sorting is according to the message checking rule Is it consistent.
具体地,例如,终端设备在按照报文核对规则中配置的排序字段,分别对该每一层级List中的多条报文数据进行排序得到排序后的报文数据之后,检测报文核对规则当中是否配置了对List中数据条数的核对规则(假定为:核对源报文数据和目标报文数据各自的条数一致,或者,核对源报文数据的条数不能少于目标报文数据的条数等),从而,如果检测到了该报文核对规则当中配置了该核对规则,则对各条源报文数据排序之后该每一层级List中的报文数据条数对应与各条目标报文数据排序之后该每一层级List中的报文数据条数进行比对以确定该条数是否相同,若核对到不相同,则返回核对失败,并记录失败原因。Specifically, for example, after the terminal device respectively sorts the multiple pieces of message data in the List of each level according to the sorting field configured in the message checking rule to obtain the sorted message data, it detects the number of items in the message checking rule. Whether the check rule for the number of data items in the List is configured (assumed to be: check that the number of items in the source message data and the target message data are the same, or, check that the number of items in the source message data cannot be less than the number of target message data number of items, etc.), thus, if it is detected that the check rule is configured in the message check rule, the number of message data items in the List of each level corresponds to each target item after sorting the source message data. After the message data is sorted, compare the number of message data items in the list of each level to determine whether the numbers are the same. If they are not the same, return the verification failure and record the reason for the failure.
步骤S405,若核对到所述第一数据条数一致,则将所述第一源字段Value值和所述第一目标字段Value值进行比对;Step S405, if it is checked that the number of the first data items is consistent, then compare the value of the first source field Value with the value of the first target field;
步骤S406,在比对得到所述第一源字段Value值和所述第一目标字段Value值相同时,得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。Step S406, when the value of the first source field Value and the value of the first target field are the same after comparison, obtain a message check result indicating that the consistency check of the JSON message to be checked is successful.
终端设备在核对到排序之后各条源报文数据和各条目标报文数据各自的第一数据条数一致时,进一步将确定得到的第一源字段Value值和第一目标字段Value值进行比对;并在比对到该第一源字段Value值和第一目标字段Value值一致时,对应的得到该待核对JSON报文中,源报文和目标报文的一致性核对成功的报文核对结果。When the terminal device checks that the number of first data pieces of each piece of source message data and each piece of target message data is consistent after sorting, it further performs the determined first source field Value value and the first target field Value value. Compare; and when comparing the first source field Value value and the first target field Value value, correspondingly obtain the message that the consistency check of the source message and the target message is successful in the JSON message to be checked. Text check results.
需要说明的是,在本实施例中,终端设备针对第一源字段Value值和第一目标字段Value值核对是否一致的过程与上述对源Value值和目标Value值核对是否一致的过程相同,在此不再做过多赘述。此外,终端设备在针对第一源字段Value值和第一目标字段Value值核对之前,还检查报文核对规则中是否存在必须核对第一条数据的配置,并且,同样的,如果存在但是核对到第二源报文和第二目标报文不符合规则,则得到报文核对结果为失败,并记录失败的原因;而终端设备针对每一层List中的每一条源报文数据或者目标报文数据,均可以按照字段逐一核对。It should be noted that, in this embodiment, the process for the terminal device to check whether the first source field Value and the first target field Value are consistent is the same as the above-mentioned process for checking whether the source Value and the target Value are consistent. I won't go into too much detail here. In addition, before the terminal device checks the first source field Value value and the first target field Value value, it also checks whether there is a configuration that must check the first piece of data in the message check rule, and, similarly, if it exists but checks to The second source message and the second target message do not conform to the rules, and the result of the message check is failure, and the reason for the failure is recorded; and the terminal device checks for each source message data or target message in each layer List The data can be checked one by one according to the fields.
进一步地,在又一种可行的实施例中,所述源Value值包括:第二源字段Value值,所述目标Value值包括:第二目标字段Value值,上述步骤S30,还可以包括:Further, in yet another feasible embodiment, the source Value includes: a second source field Value, and the target Value includes: a second target field Value. The above step S30 may also include:
步骤S305,确定预设的List_List报文核对类型在所述报文核对规则中对应的第三取值路径;Step S305, determining the third value path corresponding to the preset List_List message checking type in the message checking rule;
需要说明的是,在本实施例中,终端设备具体可以通过解析所接收到的针对待核对JSON报文进行一致性核对的请求,来获取得到该预设的List_List报文核对类型。It should be noted that, in this embodiment, the terminal device may specifically obtain the preset List_List message check type by parsing the received request for consistency check on the JSON message to be checked.
终端设备在按照获取得到报文核对规则,分别从第二源报文和第二目标报文中确定源Value值和目标Value值时,若获取到针对待核对JSON报文进行一致性核对的List_List报文核对类型,则按照该List_List报文核对类型在该第二源报文和该第二目标报文中,确定与该List_List类型相对应以用于提取第二源字段Value值和第二目标字段Value值的第三取值路径。When the terminal device determines the source value and the target value from the second source message and the second target message respectively according to the obtained message checking rules, if it obtains the List_List for consistency checking of the JSON message to be checked Message check type, then according to the List_List message check type in the second source message and the second target message, determine that it is corresponding to the List_List type for extracting the second source field Value value and the second target The third value path of the value of the field Value.
步骤S306,按照所述第三取值路径从所述第二源报文的各条源报文数据中确定所述第二源字段Value值,和按照所述第三取值路径从所述第二目标报文的各条目标报文数据中确定所述第二目标字段Value值。Step S306: Determine the value of the second source field Value from each piece of source message data in the second source message according to the third value path, and determine the value of the second source field Value from the first value path according to the third path. The value of the second target field Value is determined in each item of target message data of the second target message.
终端设备在按照List_List报文核对类型从报文核对规则当中确定出第三取值路径之后,即进一步按照该第三取值路径在多层级的第二源报文的各条源报文数据当中,获取得到每一层级源报文数据的第二源字段Value值,以及,同样按照该第三取值路径在多层级的第二目标报文的各条源报文数据当中,获取得到每一层级源报文数据的第二目标字段V alue值。After the terminal device determines the third value-taking path from the message checking rules according to the message checking type of List_List, that is, further according to the third value-taking path, among the source message data of the multi-level second source message , to obtain the second source field Value value of each level of source message data, and, also according to the third value path, among the source message data of the multi-level second target message, to obtain each The value of the second target field Value of the hierarchical source message data.
具体地,例如,假定终端设备针对待核对JSON报文中的第一源报文进行转换得到的Map数据结构的第二源报文为K,List(List)形式的WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),……)))))。如此,若终端设备获取得到List_List报文核对类型,并以该List_List报文核对类型从报文核对规则当中确定出的第三取值路径为:Key为K,则终端设备即直接按照该Key为K从第二源报文:WeMap(K,List(WeMap((K1,V1),(K2,V2),……)))中,获取到最外层List对应的源报文数据的第二源字段Value值为:Value为List(K1,List(WeMap((K2,V2),(K3,V3),……))),如此类推得到全部每一层级List对应的源报文数据的第二源字段Value值。同理,终端设备可从第二目标报文的各条源报文数据当中,获取得到每一层级源报文数据的第二目标字段Value值。Specifically, for example, it is assumed that the second source message of the Map data structure obtained by the terminal device by converting the first source message in the JSON message to be checked is WeMap(K, List(WeMap) in the form of K, List(List) (K1,List(WeMap((K2,V2),(K3,V3),...))))). In this way, if the terminal device obtains the List_List message check type, and uses the List_List message check type to determine the third value path from the message check rule: Key is K, then the terminal device directly follows the Key as K obtains the second source message data corresponding to the outermost List from the second source message: WeMap(K,List(WeMap((K1,V1),(K2,V2),...))). The Value value of the source field is: Value is List(K1,List(WeMap((K2,V2),(K3,V3),……))), and so on to get all the source message data corresponding to each level of List The value of the second source field. Similarly, the terminal device can obtain the value of the second target field of the source message data of each level from each piece of source message data in the second target message.
进一步地,上述步骤S40,还可以包括:Further, the above step S40 may also include:
步骤S407,按照层级顺序由外至内逐层核对所述源报文数据和所述目标报文数据的第二数据条数;Step S407, checking the second number of data pieces of the source message data and the target message data layer by layer from outside to inside according to the hierarchical order;
需要说明的是,在本实施例中,层级顺序为Map数据结构中每一层List指示的第二源报文和第二目标报文中,各条报文数据相互之间的层级顺序,例如,第二源报文为K,List(List)形式的WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),……)))))时,其通过List指示的最外层的源报文数据即为:WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),……))))),而其通过List指示的最里层的源报文数据为:WeMap((K2,V2),(K3,V3),……)。It should be noted that, in this embodiment, the hierarchical order is the hierarchical order of the respective message data in the second source message and the second target message indicated by each layer of List in the Map data structure, for example , when the second source message is WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),...))))) in the form of K,List(List), The outermost source message data indicated by List is: WeMap(K,List(WeMap(K1,List(WeMap((K2,V2),(K3,V3),...))))), The innermost source message data indicated by the List is: WeMap((K2, V2), (K3, V3),...).
具体地,例如,终端设备检测报文核对规则当中是否配置了对List中数据条数的核对规则,并在检测到了该报文核对规则当中配置了该核对规则时,则对各条源报文数据,依次按照通过List指示的层级顺序,对每一层级List中的源报文数据条数对应与每一层级List中的目标报文数据进行条数比对以确定该条数是否相同,若核对到条数不相同,则返回核对失败,并记录失败原因。Specifically, for example, the terminal device detects whether a check rule for the number of data items in the List is configured in the message check rule, and when it detects that the check rule is configured in the message check rule, it checks each source message Data, according to the order of levels indicated by the List, the number of source message data in each level of List is compared with the number of target message data in each level of List to determine whether the numbers are the same, if If the number of checks is not the same, return check failure and record the reason for the failure.
步骤S408,若核对到所述第二数据条数一致,则将所述第二源字段Value值和所述第二目标字段Value值进行比对;Step S408, if it is checked that the number of the second data pieces is the same, compare the value of the second source field Value with the value of the second target field;
步骤S409,在比对得到所述第二源字段Value值和所述第二目标字段Value值相同时,得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。Step S409, when the value of the second source field Value and the value of the second target field are the same after comparison, obtain a message check result indicating that the consistency check of the JSON message to be checked is successful.
终端设备在逐层核对到各条源报文数据和各条目标报文数据各自的数据条数一致时,进一步将确定得到的第二源字段Value值和第二目标字段Value值进行比对;并在比对到该第二源字段Value值和第二目标字段Value值一致时,对应的得到该待核对JSON报文中,源报文和目标报文的一致性核对成功的报文核对结果。When the terminal device checks layer by layer that the number of data pieces of each piece of source message data and each piece of target message data is consistent, it further compares the determined value of the second source field with the value of the second target field ; and when the second source field Value value is consistent with the second target field Value value, correspondingly obtain the message check that the consistency check between the source message and the target message is successful in the JSON message to be checked result.
需要说明的是,在本实施例中,终端设备针对第二源字段Value值和第二目标字段Value值核对是否一致的过程与上述对源Value值和目标Value值核对是否一致的过程相同,在此不再做过多赘述。此外,终端设备在按照层级顺序对内层List中的数据进行核对时,即基于List(WeMap(K1,List(Map((K2,V2),(K3,V3),……)))),通过报文核对规则中配置的路径:Key为K1,以确定Value值为List(WeMap((K2,V2),(K3,V3),……))进行核对,核对规则同上述终端设备在确定报文核对类型为List类型时的核对过程。It should be noted that, in this embodiment, the process for the terminal device to check whether the value of the second source field is consistent with the value of the second target field is the same as the process for checking whether the value of the source value and the target value are consistent. I won't go into too much detail here. In addition, when the terminal device checks the data in the inner List according to the hierarchical order, it is based on List(WeMap(K1,List(Map((K2,V2),(K3,V3),...)))), Through the path configured in the message check rule: Key is K1, to determine the Value value is List(WeMap((K2,V2),(K3,V3),...)) to check, the check rule is the same as the above terminal equipment in determining The verification process when the message verification type is List type.
进一步地,在一种可行的实施例中,在上述步骤S40,根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果之后,本申请JSON报文的核对方法,还可以包括:Further, in a feasible embodiment, in the above step S40, after checking according to the source Value value and the target Value value to obtain the message checking result of the JSON message to be checked, the application JSON The message checking method may also include:
步骤S60,将所述报文核对结果记录在预设核对应用关联的数据表中进行输出,其中,所述预设核对应用的运行方式为后台运行方式;或者,Step S60, recording the message checking result in a data table associated with a preset checking application for output, wherein the running mode of the preset checking application is a background running mode; or,
步骤S70,将所述报文核对结果通过预设的应用程序接口进行输出。Step S70, outputting the message checking result through a preset API.
需要说明的是,在本实施例中,如附图5所示的应用流程,终端设备可以通过核对应用在后台运行的方式来执行上述各步骤针对待核对JSON报文进行一致性核对的过程,或者,终端设备还可以通过嵌入功能业务模块的方式,由任意应用所嵌入的执行报文核对功能的业务模块,执行上述各步骤针对待核对JSON报文进行一致性核对的过程。It should be noted that, in this embodiment, as shown in the application flow shown in Figure 5, the terminal device can perform the process of performing the consistency check for the JSON message to be checked in the above steps by checking that the application is running in the background. Alternatively, the terminal device can also embed a functional business module, and the business module that performs the message checking function embedded in any application performs the above-mentioned steps to perform the process of consistency checking for the JSON message to be checked.
终端设备在通过核对应用,以后台运行方式针对待核对JSON报文进行一致性核对并得到报文核对结果之后,即将该报文核对结果直接记录在该核对应用所关联的数据表中,并基于展示该数据表来输出该报文核对结果。After the terminal device checks the consistency of the JSON message to be checked in the background operation mode through the checking application and obtains the message checking result, it will directly record the checking result of the message in the data table associated with the checking application, and based on Display the data table to output the verification result of the message.
具体地,例如,终端设备在通过核对应用基于后台运行方式进行上述对待核对JSON报文的核对过程,并得到一致性核对的报文核对结果之后,将该报文核对写入如附图4所述该核对应用的报文表(假定命名为:sys_compare_payload)的字段“compare_status”中(在报文核对结果为失败时,核对异常信息会写入字段“error_msg”中,从而在针对该报文表进行展示时,即能够针对该报文核对结果进行输出。Specifically, for example, after the terminal device performs the checking process of the JSON message to be checked based on the background operation mode through the checking application, and after obtaining the message checking result of the consistency check, the terminal device writes the message checking as shown in Figure 4 In the field "compare_status" of the message table (assumed to be named: sys_compare_payload) describing the checking application (when the message checking result is a failure, the checking exception information will be written in the field "error_msg", so that the message table When displaying, the verification result of the message can be output.
需要说明的是,在本实施中,核对应用所关联的数据表同样的可以同存储报文核对规则的核对规则库或者存储JSON报文的JSON报文库一样存储在MySQL或者SQLLite中。It should be noted that, in this implementation, the data table associated with the checking application can also be stored in MySQL or SQLLite like the checking rule library storing message checking rules or the JSON message library storing JSON messages.
终端设备在通过应用所嵌入的执行报文核对功能的业务模块针对待核对JSON报文进行一致性核对并得到报文核对结果之后,即将通过该业务模块获取该待核对JSON报文和报文核对规则时启用的应用程序接口,直接将该报文核对结果进行反馈。After the terminal device checks the consistency of the JSON message to be checked and obtains the message checking result through the business module embedded in the application that performs the message checking function, it will obtain the JSON message to be checked and the message checking result through the business module. The application program interface enabled at the time of the rule directly feeds back the verification result of the message.
具体地,例如,终端设备在通过应用中嵌入的业务模块进行上述对待核对JSON报文的核对过程,并得到一致性核对的报文核对结果之后,再次利用该业务模块获取该待核对JSON报文和报文核对规则时启用的应用程序接口——API接口,直接返回该报文核对(在报文核对结果为失败时,还通过该API接口同步核对异常信息。Specifically, for example, after the terminal device performs the above-mentioned checking process of the JSON message to be checked through the business module embedded in the application, and obtains the message checking result of the consistency check, it uses the business module again to obtain the JSON message to be checked The API interface, the application program interface enabled when checking the rules with the message, directly returns the message check (when the message check result is a failure, the exception information is also checked synchronously through the API interface.
需要说明的是,在本实施例中,终端设备设备在通过核对应用的报文表或者业务模块的应用程序接口,输出针对待核对JSON报文进行一致性核对的报文核对结果时,若该报文核对结果为失败,则终端设备还可以同步针对该待核对JSON报文不具备一致性进行告警。It should be noted that, in this embodiment, when the terminal device outputs the message check result for the consistency check of the JSON message to be checked by checking the message table of the application or the application program interface of the business module, if the If the message verification result is failure, the terminal device can also synchronously issue an alarm for the inconsistency of the to-be-checked JSON message.
在本实施例中,终端设备可以通过核对应用在后台运行的方式来执行上述各步骤针对待核对JSON报文进行一致性核对的过程,或者,终端设备还可以通过嵌入功能业务模块的方式,由任意应用所嵌入的执行报文核对功能的业务模块,执行上述各步骤针对待核对JSON报文进行一致性核对的过程。相比于传统采用Beyond Compare工具或者基于简单的Json开源包来进行JSON报文一致性比对的方式,本申请实现了以应用的方式运行在后台,直接核对源JSON报文和目标JSON报文,或者嵌入到其他应用中,通过API接口进行数据核对,提高了JSON报文一致性核对的灵活性。In this embodiment, the terminal device can perform the process of checking the consistency of the JSON message to be checked in the above steps by checking that the application is running in the background, or the terminal device can also be embedded in a functional business module. The business module that performs the message checking function embedded in any application executes the above-mentioned steps to check the consistency of the JSON message to be checked. Compared with the traditional way of using the Beyond Compare tool or based on the simple Json open source package to compare the consistency of JSON messages, this application implements running in the background as an application to directly check the source JSON message and the target JSON message , or embedded into other applications, and perform data verification through the API interface, which improves the flexibility of JSON message consistency verification.
本申请提供的JSON报文的核对方法,通过终端设备从存储JSON报文的数据库中获取当前需要进行一致性核对的待核对JSON报文,并从存储报文核对规则的核对规则库当中,获取用于针对该待核对JSON报文进行一致性核对的报文核对规则;将该待核对JSON报文当中的第一源报文,转换为Map数据结构的第二源报文,并且,还将该待核对JSON报文当中的第一目标报文,也转换为Map数据结构的第二目标报文;按照已经获取得到用于针对该待核对JSON报文进行一致性核对的报文核对规则,在该第二源报文确定源Value值,和在该第二目标报文当中确定目标Value值以供后续进行核对;通过比对该源Value值和该目标Value值是否相同,并在确定相同时,对应的得到该待核对JSON报文中,源报文和目标报文的一致性核对成功的报文核对结果,否则,在确定不相同时,对应的得到该待核对JSON报文中,源报文和目标报文的一致性核对失败的报文核对结果。The checking method of the JSON message provided by this application is to obtain the JSON message to be checked that currently needs to be checked for consistency from the database storing the JSON message through the terminal device, and obtain from the checking rule base storing the message checking rules. A message checking rule for consistency checking of the JSON message to be checked; the first source message in the JSON message to be checked is converted into a second source message of the Map data structure, and the The first target message in the JSON message to be checked is also converted into the second target message of the Map data structure; according to the message checking rule obtained for the consistency check of the JSON message to be checked, Determine the source Value value in the second source message, and determine the target Value value in the second target message for subsequent checking; by comparing whether the source Value value and the target Value value are the same, and determine the corresponding Simultaneously, in the JSON message to be checked, the message checking result of the consistency check of the source message and the target message is obtained correspondingly; otherwise, when it is determined that they are different, correspondingly, in the JSON message to be checked, The check result of the message that the consistency check between the source message and the target message fails.
相比于传统采用Beyond Compare工具或者基于简单的Json开源包来进行JSON报文一致性比对的方式,本申请通过将JSON报文转换为Map数据结构,并按照预先配置的报 文核对规则基于该Map数据结构确定Value值进行报文一致性核对,如此,能够实现便捷且准确的针对JSON报文的任意字段进行处理及核对,有效地避免了传统方式无法实现核对的情形,提升了JSON报文一致性核对的效率。Compared with the traditional method of using the Beyond Compare tool or based on the simple Json open source package for JSON message consistency comparison, this application converts the JSON message into a Map data structure, and according to the pre-configured message check rules based on The Map data structure determines the Value value to check the consistency of the message. In this way, it can realize convenient and accurate processing and checking of any field of the JSON message, effectively avoiding the situation that the traditional method cannot be checked, and improving the JSON report. The efficiency of document consistency check.
此外,本申请还提供一种JSON报文的核对装置,请参照图6,所述JSON报文的核对装置包括:In addition, the present application also provides a checking device for a JSON message, please refer to Figure 6, the checking device for the JSON message includes:
报文核对准备模块10,用于获取待核对JSON报文和预设的报文核对规则,其中,所述报文核对规则基于所述待核对JSON报文进行配置得到;The message check preparation module 10 is used to obtain the JSON message to be checked and a preset message check rule, wherein the message check rule is configured based on the JSON message to be checked;
报文转换模块20,用于将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文,并将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文; Message conversion module 20, for converting the first source message in the JSON message to be checked into the second source message of the Map data structure, and converting the first target message in the JSON message to be checked The text is converted into the second target message of the Map data structure;
Value确定模块30,用于若比对得到所述第二源报文与所述第二目标报文的MD5值不一致,则按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值; Value determination module 30, configured to determine the source from the second source message according to the message checking rules if the MD5 values of the second source message and the second target message are inconsistent after comparison Value value, and determine the target Value value from the second target message according to the message checking rule;
核对模块40,用于根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果。A checking module 40, configured to check according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
进一步地,所述源Value值包括:内层源Value值,所述目标Value值包括:内层目标Value值,Value确定模块30,包括:Further, the source Value value includes: an inner layer source Value value, and the target Value value includes: an inner layer target Value value, and the Value determination module 30 includes:
第一路径确定单元,用于确定预设的Value报文核对类型在所述报文核对规则中对应的第一取值路径;A first path determination unit, configured to determine a first value path corresponding to the preset Value message check type in the message check rule;
第一Value确定单元,用于按照所述第一取值路径从所述第二源报文中确定所述内层源Value值,和按照所述取值路径从所述第二目标报文中确定所述内层目标Value值;A first Value determination unit, configured to determine the inner source Value value from the second source message according to the first value path, and determine the inner source Value value from the second target message according to the value path determining the inner target Value;
核对模块40,包括:Check module 40, including:
第一比对单元,用于将所述内层源Value值与所述内层目标Value值进行比对得到比对结果;A first comparison unit, configured to compare the inner source Value with the inner target Value to obtain a comparison result;
第一结果确定单元,用于若所述比对结果为所述内层源Value值和所述内层目标Value值相同,则得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。The first result determination unit is configured to obtain a message that the consistency check of the JSON message to be checked is successful if the comparison result is that the inner source value and the inner target value are the same. Check the results.
进一步地,所述源Value值包括:第一源字段Value值,所述目标Value值包括:第一目标字段Value值,Value确定模块30,包括:Further, the source Value value includes: a first source field Value value, and the target Value value includes: a first target field Value value, and the Value determination module 30 includes:
第二路径确定单元,用于确定预设的List报文核对类型在所述报文核对规则中对应的第二取值路径;A second path determination unit, configured to determine a second value path corresponding to the preset List message check type in the message check rule;
第二Value确定单元,用于按照所述第二取值路径从所述第二源报文的各条源报文数据中确定所述第一源字段Value值,和按照所述第二取值路径从所述第二目标报文的各条源报文数据中确定所述第一目标字段Value值。A second Value determination unit, configured to determine the value of the first source field Value from each piece of source message data in the second source message according to the second value path, and according to the second value path The path determines the value of the first target field Value from each piece of source message data in the second target message.
进一步地,核对模块40,包括:Further, the checking module 40 includes:
排序单元,用于按照所述List类型在所述报文核对规则中对应的排序方式,对各所述源报文数据和各所述目标报文数据进行排序;A sorting unit, configured to sort each of the source message data and each of the target message data according to the sorting manner corresponding to the List type in the message checking rule;
第一核对单元,用于核对经过排序后的各所述源报文数据和各所述目标报文数据各自的第一数据条数是否一致;A first checking unit, configured to check whether the number of first pieces of data in each of the sorted source message data and each of the target message data is consistent;
第二比对单元,用于若核对到所述第一数据条数一致,则将所述第一源字段Value值和所述第一目标字段Value值进行比对;The second comparison unit is configured to compare the value of the first source field with the value of the first target field if the number of the first data pieces is checked to be consistent;
第二结果确定单元,用于在比对得到所述第一源字段Value值和所述第一目标字段Value值相同时,得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。The second result determination unit is configured to obtain a message check that the consistency check of the JSON message to be checked is successful when the value of the first source field is the same as that of the first target field. result.
进一步地,所述源Value值包括:第二源字段Value值,所述目标Value值包括:第二目标字段Value值,Value确定模块30,包括:Further, the source Value value includes: a second source field Value value, and the target Value value includes: a second target field Value value, and the Value determination module 30 includes:
第三路径确定单元,用于确定预设的List_List报文核对类型在所述报文核对规则中对应的第三取值路径;A third path determination unit, configured to determine a third value path corresponding to the preset List_List message check type in the message check rule;
第三Value确定单元,用于按照所述第三取值路径从所述第二源报文的各条源报文数据中确定所述第二源字段Value值,和按照所述第三取值路径从所述第二目标报文的各条目标报文数据中确定所述第二目标字段Value值。A third Value determination unit, configured to determine the value of the second source field Value from each piece of source message data in the second source message according to the third value path, and according to the third value path The path determines the value of the second target field Value from each item of target message data in the second target message.
进一步地,核对模块40,包括:Further, the checking module 40 includes:
第二核对单元,用于按照层级顺序由外至内逐层核对所述源报文数据和所述目标报文数据的第二数据条数;The second checking unit is configured to check the second number of data pieces of the source message data and the target message data layer by layer from outside to inside according to the hierarchical order;
第三比对单元,用于若核对到所述第二数据条数一致,则将所述第二源字段Value值和所述第二目标字段Value值进行比对;A third comparison unit, configured to compare the second source field Value with the second target field Value if the number of the second data pieces is found to be consistent;
第三结果确定单元,用于在比对得到所述第二源字段Value值和所述第二目标字段Value值相同时,得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。The third result determination unit is configured to obtain a message check that the consistency check of the JSON message to be checked is successful when the value of the second source field Value and the value of the second target field are the same after comparison. result.
进一步地,本申请JSON报文的核对装置,还包括:Further, the checking device of the JSON message of the present application also includes:
生成模块,用于获取预设的报文核对需求,并解析所述待核对JSON报文的数据结构,以按照所述报文核对需求生成所述数据结构对应的用于对所述待核对JSON报文进行一致性核对的报文核对规则。A generating module, configured to obtain a preset message checking requirement, and parse the data structure of the JSON message to be checked, so as to generate the data structure corresponding to the JSON message to be checked according to the message checking requirement. Packet checking rules for checking the consistency of the packets.
进一步地,在所述根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果之后,所述装置还包括:Further, after the checking according to the source Value and the target Value to obtain the message checking result of the JSON message to be checked, the device further includes:
第一输出模块,用于将所述报文核对结果记录在预设核对应用关联的数据表中进行输出,其中,所述预设核对应用的运行方式为后台运行方式;或者,The first output module is configured to record the message checking result in a data table associated with a preset checking application for output, wherein the running mode of the preset checking application is a background running mode; or,
第二输出模块,用于将所述报文核对结果通过预设的应用程序接口进行输出。The second output module is configured to output the message checking result through a preset application program interface.
进一步地,所述Map数据结构包括:普通型Map数据结构和嵌套型Map数据结构,Further, the Map data structure includes: a common Map data structure and a nested Map data structure,
所述报文转换模块20还用于:The message conversion module 20 is also used for:
在所述第一源报文中确定普通形式的第一报文数据和/或者嵌套形式的第二报文数据;determining the first message data in normal form and/or the second message data in nested form in the first source message;
将所述第一报文数据转换为所述普通型Map数据结构的第二源报文,和/或者,将所述第二报文数据转换为所述嵌套型Map数据结构的第二源报文;Converting the first message data into a second source message of the common Map data structure, and/or converting the second message data into a second source of the nested Map data structure message;
所述报文转换模块20还用于:The message conversion module 20 is also used for:
在所述第一目标报文中确定普通形式的第三报文数据和/或者嵌套形式的第四报文数据;determining the third message data in common form and/or the fourth message data in nested form in the first target message;
将所述第三报文数据转换为所述普通型Map数据结构的第二目标报文,和/或者,将所述第四报文数据转换为所述嵌套型Map数据结构的第二目标报文。Converting the third message data into a second target message of the common Map data structure, and/or converting the fourth message data into a second target of the nested Map data structure message.
进一步地,所述报文转换模块20还用于:Further, the message conversion module 20 is also used for:
循环检测所述第四报文数据的各嵌套层级中健值对应的Value值类型,其中,所述Value值类型包括:普通Value值、JSON数组和JSON对象;Circularly detect the Value value type corresponding to the key value in each nested level of the fourth message data, wherein the Value value type includes: ordinary Value value, JSON array and JSON object;
若检测到所述Value值类型为所述普通Value值,则将所述键值记录为Map数据结构以得到所述第二目标报文。If it is detected that the type of the Value is the normal Value, then recording the key value as a Map data structure to obtain the second target message.
上述各程序单元所执行的方法可参照本申请JSON报文的核对方法各个实施例,此处不再赘述。For the methods executed by the above program units, reference may be made to the various embodiments of the method for checking JSON messages in this application, which will not be repeated here.
本申请还提供一种JSON报文的核对设备,JSON报文的核对设备包括:存储器、处理器及存储在存储器上并可在处理器上运行的JSON报文的核对程序,JSON报文的核对程序被处理器执行时所实现的方法可参照本申请JSON报文的核对方法各个实施例,此处不再赘述。The application also provides a checking device for a JSON message. The checking device for a JSON message includes: a memory, a processor, and a checking program for a JSON message stored on the memory and operable on the processor. For the methods implemented when the program is executed by the processor, reference may be made to the various embodiments of the method for checking JSON messages in this application, and details will not be repeated here.
本申请还提供一种计算机存储介质。The present application also provides a computer storage medium.
本申请计算机存储介质上存储有JSON报文的核对程序,所述JSON报文的核对程序 被处理器执行时实现如上所述的JSON报文的核对方法的步骤。The checking program of the JSON message is stored on the computer storage medium of the application, and the checking program of the JSON message is implemented when the processor executes the steps of the checking method of the JSON message as described above.
其中,在所述处理器上运行的JSON报文的核对程序被执行时所实现的方法可参照本申请JSON报文的核对方法各个实施例,此处不再赘述。Wherein, the method implemented when the JSON message checking program running on the processor is executed can refer to the various embodiments of the JSON message checking method in this application, and will not be repeated here.
本申请还提供一种计算机程序产品。The present application also provides a computer program product.
本申请计算机程序产品包括JSON报文的核对程序,所述JSON报文的核对程序被处理器执行时实现如上所述的JSON报文的核对方法的步骤。The computer program product of the present application includes a JSON message checking program, and when the JSON message checking program is executed by a processor, the steps of the JSON message checking method described above are implemented.
其中,在所述处理器上运行的JSON报文的核对程序被执行时所实现的方法可参照本申请JSON报文的核对方法各个实施例,此处不再赘述。Wherein, the method implemented when the JSON message checking program running on the processor is executed can refer to the various embodiments of the JSON message checking method in this application, and will not be repeated here.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。It should be noted that, as used herein, the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article or system comprising a set of elements includes not only those elements, It also includes other elements not expressly listed, or elements inherent in the process, method, article, or system. Without further limitations, an element defined by the phrase "comprising a ..." does not preclude the presence of additional identical elements in the process, method, article or system comprising that element.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the above embodiments of the present application are for description only, and do not represent the advantages and disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,空调器,或者网络设备等)执行本申请各个实施例所述的方法。Through the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general-purpose hardware platform, and of course also by hardware, but in many cases the former is better implementation. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product in essence or the part that contributes to the prior art, and the computer software product is stored in a storage medium as described above (such as ROM/RAM , magnetic disk, optical disk), including several instructions to make a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) execute the methods described in various embodiments of the present application.
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structures or equivalent process transformations made by using the contents of the specification and drawings of this application, or directly or indirectly used in other related technical fields , are all included in the patent protection scope of the present application in the same way.

Claims (10)

  1. 一种JSON报文的核对方法,其中,所述JSON报文的核对方法包括:A checking method of JSON message, wherein, the checking method of described JSON message comprises:
    获取待核对JSON报文和预设的报文核对规则,其中,所述报文核对规则基于所述待核对JSON报文进行配置得到;Obtaining the JSON message to be checked and a preset message checking rule, wherein the message checking rule is configured based on the JSON message to be checked;
    将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文,并将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文;Converting the first source message in the JSON message to be checked into the second source message of the Map data structure, and converting the first target message in the JSON message to be checked into the first source message of the Map data structure Two target messages;
    若比对得到所述第二源报文与所述第二目标报文的MD5值不一致,则按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值;If the comparison shows that the MD5 values of the second source message and the second target message are inconsistent, then determine the source Value value from the second source message according to the message check rule, and according to the Determine the target Value value from the second target message according to the message checking rule;
    根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果。Checking is performed according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
  2. 如权利要求1所述的JSON报文的核对方法,其中,所述源Value值包括:内层源Value值,所述目标Value值包括:内层目标Value值,The checking method of JSON message as claimed in claim 1, wherein, said source Value value comprises: inner layer source Value value, and said target Value value comprises: inner layer target Value value,
    所述按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值的步骤,包括:The steps of determining the source value from the second source message according to the message checking rule, and determining the target value from the second target message according to the message checking rule include:
    确定预设的Value报文核对类型在所述报文核对规则中对应的第一取值路径;Determine the first value path corresponding to the preset Value message check type in the message check rule;
    按照所述第一取值路径从所述第二源报文中确定所述内层源Value值,和按照所述取值路径从所述第二目标报文中确定所述内层目标Value值;determining the inner source value from the second source message according to the first value path, and determining the inner target value from the second target message according to the value path ;
    所述根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果的步骤,包括:The step of checking according to the source Value and the target Value to obtain the message checking result of the JSON message to be checked includes:
    将所述内层源Value值与所述内层目标Value值进行比对得到比对结果;Comparing the inner source Value with the inner target Value to obtain a comparison result;
    若所述比对结果为所述内层源Value值和所述内层目标Value值相同,则得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。If the comparison result is that the inner source Value is the same as the inner target Value, a message check result indicating that the consistency check of the JSON message to be checked is successful is obtained.
  3. 如权利要求1所述的JSON报文的核对方法,其中,所述源Value值包括:第一源字段Value值,所述目标Value值包括:第一目标字段Value值,The checking method of JSON message according to claim 1, wherein, the source Value value comprises: the first source field Value value, and the target Value value comprises: the first target field Value value,
    所述按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值的步骤,包括:The steps of determining the source value from the second source message according to the message checking rule, and determining the target value from the second target message according to the message checking rule include:
    确定预设的List报文核对类型在所述报文核对规则中对应的第二取值路径;Determine the second value path corresponding to the preset List message check type in the message check rule;
    按照所述第二取值路径从所述第二源报文的各条源报文数据中确定所述第一源字段Value值,和按照所述第二取值路径从所述第二目标报文的各条源报文数据中确定所述第一目标字段Value值。Determine the value of the first source field Value from each source message data of the second source message according to the second value path, and determine the value of the first source field Value from the second target message according to the second value path. Determine the value of the first target field Value in each piece of source message data in the text.
  4. 如权利要求3所述的JSON报文的核对方法,其中,所述根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果的步骤,包括:The checking method of JSON message as claimed in claim 3, wherein, the step of checking according to the source Value value and the target Value value to obtain the message checking result of the JSON message to be checked includes :
    按照所述List类型在所述报文核对规则中对应的排序方式,对各所述源报文数据和各所述目标报文数据进行排序;sorting each of the source message data and each of the target message data according to the sorting manner corresponding to the List type in the message checking rule;
    核对经过排序后的各所述源报文数据和各所述目标报文数据各自的第一数据条数是否一致;Check whether the number of the first data pieces of each of the source message data after sorting and each of the target message data is consistent;
    若核对到所述第一数据条数一致,则将所述第一源字段Value值和所述第一目标字段Value值进行比对;If it is checked that the number of the first data pieces is consistent, then comparing the value of the first source field with the value of the first target field;
    在比对得到所述第一源字段Value值和所述第一目标字段Value值相同时,得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。When the value of the first source field Value is the same as the value of the first target field, a message check result indicating that the consistency check of the JSON message to be checked is successful is obtained.
  5. 如权利要求1所述的JSON报文的核对方法,其中,所述源Value值包括:第二源字段Value值,所述目标Value值包括:第二目标字段Value值,The checking method of JSON message according to claim 1, wherein, the source Value value comprises: the second source field Value value, and the target Value value comprises: the second target field Value value,
    所述按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值的步骤,包括:The steps of determining the source value from the second source message according to the message checking rule, and determining the target value from the second target message according to the message checking rule include:
    确定预设的List_List报文核对类型在所述报文核对规则中对应的第三取值路径;Determine the third value path corresponding to the preset List_List message check type in the message check rule;
    按照所述第三取值路径从所述第二源报文的各条源报文数据中确定所述第二源字段Value值,和按照所述第三取值路径从所述第二目标报文的各条目标报文数据中确定所述第二目标字段Value值。Determine the value of the second source field Value from each piece of source message data in the second source message according to the third value path, and determine the value of the second source field from the second target message according to the third value path. Determine the value of the second target field Value in each item of target message data in the text.
  6. 如权利要求5所述的JSON报文的核对方法,其中,所述根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果的步骤,包括:The checking method of JSON message as claimed in claim 5, wherein, the step of checking according to the source Value value and the target Value value to obtain the message checking result of the JSON message to be checked includes :
    按照层级顺序由外至内逐层核对所述源报文数据和所述目标报文数据的第二数据条数;Checking the second number of data pieces of the source message data and the target message data layer by layer from outside to inside according to the hierarchical order;
    若核对到所述第二数据条数一致,则将所述第二源字段Value值和所述第二目标字段Value值进行比对;If it is checked that the number of the second data pieces is consistent, then comparing the value of the second source field Value with the value of the second target field;
    在比对得到所述第二源字段Value值和所述第二目标字段Value值相同时,得到对所述待核对JSON报文进行一致性核对成功的报文核对结果。When the value of the second source field Value is the same as that of the second target field Value, a message check result indicating that the consistency check of the to-be-checked JSON message is successful is obtained.
  7. 如权利要求1所述的JSON报文的核对方法,其中,所述方法还包括:The checking method of JSON message as claimed in claim 1, wherein, described method also comprises:
    获取预设的报文核对需求,并解析所述待核对JSON报文的数据结构,以按照所述报文核对需求生成所述数据结构对应的用于对所述待核对JSON报文进行一致性核对的报文核对规则。Obtaining the preset message checking requirements, and parsing the data structure of the JSON message to be checked, so as to generate the data structure corresponding to the message checking requirement for consistency of the JSON message to be checked Checked packet check rules.
  8. 如权利要求1所述的JSON报文的核对方法,其中,所述Map数据结构包括:普通型Map数据结构和嵌套型Map数据结构,The checking method of JSON message as claimed in claim 1, wherein, described Map data structure comprises: common type Map data structure and nested type Map data structure,
    所述将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文的步骤,包括:The step of converting the first source message in the JSON message to be checked into the second source message of the Map data structure includes:
    在所述第一源报文中确定普通形式的第一报文数据和/或者嵌套形式的第二报文数据;determining the first message data in normal form and/or the second message data in nested form in the first source message;
    将所述第一报文数据转换为所述普通型Map数据结构的第二源报文,和/或者,将所述第二报文数据转换为所述嵌套型Map数据结构的第二源报文;Converting the first message data into a second source message of the common Map data structure, and/or converting the second message data into a second source of the nested Map data structure message;
    所述将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文的步骤,包括:The step of converting the first target message in the JSON message to be checked into the second target message of the Map data structure includes:
    在所述第一目标报文中确定普通形式的第三报文数据和/或者嵌套形式的第四报文数据;determining the third message data in common form and/or the fourth message data in nested form in the first target message;
    将所述第三报文数据转换为所述普通型Map数据结构的第二目标报文,和/或者,将所述第四报文数据转换为所述嵌套型Map数据结构的第二目标报文。Converting the third message data into a second target message of the common Map data structure, and/or converting the fourth message data into a second target of the nested Map data structure message.
  9. 如权利要求8所述的JSON报文的核对方法,其中,所述将所述第四报文数据转换为所述嵌套型Map数据结构的第二目标报文的步骤,包括:The checking method of the JSON message as claimed in claim 8, wherein, the step of converting the fourth message data into the second target message of the nested Map data structure comprises:
    循环检测所述第四报文数据的各嵌套层级中健值对应的Value值类型,其中,所述Value值类型包括:普通Value值、JSON数组和JSON对象;Circularly detect the Value value type corresponding to the key value in each nested level of the fourth message data, wherein the Value value type includes: ordinary Value value, JSON array and JSON object;
    若检测到所述Value值类型为所述普通Value值,则将所述键值记录为Map数据结构以得到所述第二目标报文。If it is detected that the type of the Value is the normal Value, then recording the key value as a Map data structure to obtain the second target message.
  10. 一种JSON报文的核对装置,其中,所述JSON报文的核对装置包括:A checking device of JSON message, wherein, the checking device of described JSON message comprises:
    报文核对准备模块,用于获取待核对JSON报文和预设的报文核对规则,其中,所述报文核对规则基于所述待核对JSON报文进行配置得到;A message check preparation module, configured to obtain a JSON message to be checked and a preset message check rule, wherein the message check rule is configured based on the JSON message to be checked;
    报文转换模块,用于将所述待核对JSON报文中的第一源报文转换为Map数据结构的第二源报文,并将所述待核对JSON报文中的第一目标报文转换为Map数据结构的第二目标报文;A message conversion module, configured to convert the first source message in the JSON message to be checked into the second source message of the Map data structure, and convert the first target message in the JSON message to be checked Be converted into the second target message of Map data structure;
    Value确定模块,用于若比对得到所述第二源报文与所述第二目标报文的MD5值不 一致,则按照所述报文核对规则从所述第二源报文中确定源Value值,和按照所述报文核对规则从所述第二目标报文中确定目标Value值;A Value determination module, configured to determine the source Value from the second source message according to the message checking rules if the MD5 values of the second source message and the second target message are inconsistent after comparison value, and determine the target Value value from the second target message according to the message checking rule;
    核对模块,用于根据所述源Value值和所述目标Value值进行核对以得到所述待核对JSON报文的报文核对结果。A checking module, configured to check according to the source Value and the target Value to obtain a message checking result of the to-be-checked JSON message.
PCT/CN2021/139563 2021-06-30 2021-12-20 Json packet checking method and json packet checking apparatus WO2023273218A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110746878.X 2021-06-30
CN202110746878.XA CN113489593B (en) 2021-06-30 2021-06-30 JSON message checking method and JSON message checking device

Publications (1)

Publication Number Publication Date
WO2023273218A1 true WO2023273218A1 (en) 2023-01-05

Family

ID=77939273

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/139563 WO2023273218A1 (en) 2021-06-30 2021-12-20 Json packet checking method and json packet checking apparatus

Country Status (2)

Country Link
CN (1) CN113489593B (en)
WO (1) WO2023273218A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370398A (en) * 2023-11-15 2024-01-09 航天信息(广东)有限公司 Comparison method and device for changing data

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113489593B (en) * 2021-06-30 2022-11-08 深圳前海微众银行股份有限公司 JSON message checking method and JSON message checking device
CN114338835A (en) * 2021-12-31 2022-04-12 中企云链(北京)金融信息服务有限公司 Data message dynamic conversion method and device, storage medium and electronic device

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110162509A (en) * 2019-04-26 2019-08-23 平安普惠企业管理有限公司 File comparison method, device, computer equipment and storage medium
CN110377704A (en) * 2019-07-22 2019-10-25 北京百度网讯科技有限公司 Detection method, device and the computer equipment of data consistency
CN112084109A (en) * 2020-09-01 2020-12-15 中国银联股份有限公司 System test method, apparatus, device and medium
US20210034587A1 (en) * 2019-08-02 2021-02-04 Timescale, Inc. Type-specific compression in database systems
CN112416944A (en) * 2020-12-03 2021-02-26 云知声智能科技股份有限公司 Method and equipment for synchronizing service data
CN113489593A (en) * 2021-06-30 2021-10-08 深圳前海微众银行股份有限公司 JSON message checking method and JSON message checking device

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107547688B (en) * 2017-09-06 2020-07-10 新华三技术有限公司 Message processing method and device
CN111181857B (en) * 2018-11-09 2020-12-29 深圳市中兴微电子技术有限公司 Message processing method and device, storage medium and optical network terminal
CN110912655B (en) * 2019-12-24 2023-01-20 瑞斯康达科技发展股份有限公司 Data redundancy backup method, device, equipment and medium
CN112491901B (en) * 2020-11-30 2023-03-24 北京锐驰信安技术有限公司 Network flow fine screening device and method
CN112699137B (en) * 2021-01-04 2023-09-12 远光软件股份有限公司 Cross-system financial data processing method and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110162509A (en) * 2019-04-26 2019-08-23 平安普惠企业管理有限公司 File comparison method, device, computer equipment and storage medium
CN110377704A (en) * 2019-07-22 2019-10-25 北京百度网讯科技有限公司 Detection method, device and the computer equipment of data consistency
US20210034587A1 (en) * 2019-08-02 2021-02-04 Timescale, Inc. Type-specific compression in database systems
CN112084109A (en) * 2020-09-01 2020-12-15 中国银联股份有限公司 System test method, apparatus, device and medium
CN112416944A (en) * 2020-12-03 2021-02-26 云知声智能科技股份有限公司 Method and equipment for synchronizing service data
CN113489593A (en) * 2021-06-30 2021-10-08 深圳前海微众银行股份有限公司 JSON message checking method and JSON message checking device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117370398A (en) * 2023-11-15 2024-01-09 航天信息(广东)有限公司 Comparison method and device for changing data

Also Published As

Publication number Publication date
CN113489593A (en) 2021-10-08
CN113489593B (en) 2022-11-08

Similar Documents

Publication Publication Date Title
WO2023273218A1 (en) Json packet checking method and json packet checking apparatus
US9483386B2 (en) Information interaction test device and method based on automatic generation of associated test cases
CN101930400B (en) SDK (Software Development Kit) automatic test system and method
US20210073478A1 (en) Systems and methods for dynamically expanding natural language processing agent capacity
US20200210423A1 (en) Multi-party data joint query method, device, server and storage medium
CN112181804B (en) Parameter verification method, device and storage medium
US20210034594A1 (en) Creating index in blockchain-type ledger
CN109740129B (en) Report generation method, device and equipment based on blockchain and readable storage medium
CN109800258A (en) Data file dispositions method, device, computer equipment and storage medium
CN111026670B (en) Test case generation method, test case generation device and storage medium
CN109871289A (en) A kind of remote procedure call service creation method and device
CN113839977A (en) Message pushing method and device, computer equipment and storage medium
CN112232881A (en) Data detection method and device, electronic equipment and storage medium
CN115237805A (en) Test case data preparation method and device
CN107276912B (en) Memory, message processing method and distributed storage system
CN114168149A (en) Data conversion method and device
CN112395339B (en) Intersystem data admission verification method, device, computer equipment and storage medium
CN112235124B (en) Method and device for configuring pico-cell, storage medium and electronic device
CN110764760B (en) Method, apparatus, computer system, and medium for drawing program flow chart
US20110213663A1 (en) Service intelligence module program product
CN114866627A (en) Message checking method, device, processor and electronic equipment
CN113742529A (en) Multi-table front-end processing method and device
CN110728118B (en) Cross-data-platform data processing method, device, equipment and storage medium
CN113312075A (en) Configuration information issuing method and device, storage medium and processor
CN117573730B (en) Data processing method, apparatus, device, readable storage medium, and program product

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21948143

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE