CN113489593B - JSON message checking method and JSON message checking device - Google Patents

JSON message checking method and JSON message checking device Download PDF

Info

Publication number
CN113489593B
CN113489593B CN202110746878.XA CN202110746878A CN113489593B CN 113489593 B CN113489593 B CN 113489593B CN 202110746878 A CN202110746878 A CN 202110746878A CN 113489593 B CN113489593 B CN 113489593B
Authority
CN
China
Prior art keywords
message
value
source
checking
json
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202110746878.XA
Other languages
Chinese (zh)
Other versions
CN113489593A (en
Inventor
夏柱昌
夏勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
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 WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202110746878.XA priority Critical patent/CN113489593B/en
Publication of CN113489593A publication Critical patent/CN113489593A/en
Priority to PCT/CN2021/139563 priority patent/WO2023273218A1/en
Application granted granted Critical
Publication of CN113489593B publication Critical patent/CN113489593B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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]

Abstract

The invention relates to the technical field of financial science and technology (Fintech), and discloses a JSON message checking method and a JSON message checking device, wherein the method comprises the following steps: acquiring a JSON message to be checked and a preset message checking rule, wherein the message checking rule is obtained by configuring based on the JSON message to be checked; converting a first source message in the JSON message to be checked into a second source message of a Map data structure, and converting a first target message in the JSON message to be checked into a second target message of the Map data structure; if the MD5 values of the second source message and the second target message are inconsistent, determining a source Value from the second source message according to a message check rule, and determining a target Value from the second target message according to the message check rule; and checking according to the source Value and the target Value to obtain a message checking result of the JSO N message to be checked. The invention can improve the efficiency of consistency check of the JSON message.

Description

JSON message checking method and JSON message checking device
Technical Field
The invention relates to the technical field of financial technology (Fintech), in particular to a JSON message checking method and a JSON message checking device.
Background
With the development of computer technology, more and more technologies (big data, distributed, block chain blockchain, artificial intelligence, etc.) are applied in the financial field, and the traditional financial industry is gradually changing to financial technology (Fintech), but because of the requirements of security and real-time performance of the financial industry, higher requirements are provided for the consistency checking technology of JSON messages.
In the present invention, json (Java Script Object Notation, json Object Notation, a lightweight data exchange format, JS is entirely called Java Script, and is a programming language) messages are widely applied in scenarios such as message transmission between API interfaces and between application front and back ends, and in particular, for Java (one-Object oriented programming language) application development and data testing, checking whether Json messages before and after interface change are consistent, checking whether Json messages of the same data source are consistent after multiparty processing, and the like are necessary and frequent operations.
Currently, a commonly used JSON packet checking method is to Compare data consistency with a tool such as Beyond company (a text file comparison tool) or based on a simple JSON open source packet. However, these checking methods cannot realize the checking of data consistency under the conditions that the data nesting level of the JSON message is deep, the field is changed, or an unordered data list exists in the JSON message, and the like, so that the efficiency of checking the consistency of the JSON message is low.
Disclosure of Invention
The invention mainly aims to provide a JSON message checking method and a JSON message checking device, and aims to solve the technical problem that the existing checking efficiency for consistency checking of JSON messages is low.
In order to achieve the above object, the present invention provides a method for checking a JSON packet, wherein the method for checking a JSON packet comprises the following steps:
acquiring a JSON message to be checked and a preset message checking rule, wherein the message checking rule is obtained by configuring based on the JSON message to be checked;
converting a first source message in the JSON message to be checked into a second source message of a Map data structure, and converting a first target message in the JSON message to be checked into a second target message of the Map data structure;
if the MD5 values of the second source message and the second target message are not consistent after comparison, determining a source Value from the second source message according to the message check rule, and determining a target Value from the second target message according to the message check rule;
and checking according to the source Value and the target Value to obtain a message checking result of the JSO N message to be checked.
In addition, to achieve the above object, the present invention further provides a device for checking a JSON packet, where the device for checking a JSON packet includes:
the message checking preparation module is used for acquiring a JSON message to be checked and a preset message checking rule, wherein the message checking rule is obtained by configuring the JSON message to be checked based on the JSON message to be checked;
the message conversion module is used for converting a first source message in the JSON message to be checked into a second source message of a Map data structure and converting a first target message in the JSON message to be checked into a second target message of the Map data structure;
a Value determining module, configured to determine a source Value from the second source packet according to the packet check rule and determine a destination Value from the second destination packet according to the packet check rule if the MD5 values of the second source packet and the second destination packet obtained by the comparison are inconsistent;
and the checking module is used for checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked.
The method for checking the JSON message comprises the following steps of carrying out JSON message checking on the JSON message, and carrying out JSON message checking on the JSON message.
In addition, to achieve the above object, the present invention also provides a terminal device, including: the device comprises a memory, a processor and a checking program of the JSON message, wherein the checking program of the JSON message is stored on the memory and can run on the processor, and when being executed by the processor, the checking program of the JSON message realizes the steps of the checking method of the JSON message.
In addition, to achieve the above object, the present invention further provides a computer storage medium having stored thereon a JSON packet collation program, which when executed by a processor, implements the steps of the above JSON packet collation method.
In addition, to achieve the above object, the present invention further provides a computer program product, where the computer program product includes a JSON packet collation program, and the JSON packet collation program implements the steps of the JSON packet collation method described above when being executed by a processor.
The method comprises the steps of obtaining a JSON message to be checked and a preset message checking rule, wherein the message checking rule is obtained by configuring the JSON message to be checked based on the JSON message to be checked; converting a first source message in the JSON message to be checked into a second source message of a Map data structure, and converting a first target message in the JSON message to be checked into a second target message of the Map data structure; if the MD5 values of the second source message and the second target message are not consistent after comparison, determining a source Value from the second source message according to the message check rule, and determining a target Value from the second target message according to the message check rule; and checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked.
Compared with the traditional mode of performing JSON message consistency comparison by adopting a Beyond compact tool or based on a simple Json source-opening packet, the JSON message consistency comparison method based on the JSON message is characterized in that the JSON message is converted into a Map data structure, and the Value is determined based on the Map data structure according to the preconfigured message comparison rule to perform message consistency comparison, so that any field of the JSON message can be conveniently and accurately processed and checked, the situation that the checking cannot be realized in the traditional mode is effectively avoided, and the JSON message consistency comparison efficiency is improved.
Drawings
Fig. 1 is a schematic diagram of a checking device structure of a JSON packet in a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a schematic flow chart of an embodiment of a JSON message checking method of the present invention;
fig. 3 is a field description in a message collation rule according to an embodiment of a JSON message collation method of the present invention;
fig. 4 is a data table related to a preset checking application association according to the embodiment of the JSON packet checking method of the present invention;
fig. 5 is a schematic view of an application flow related to an embodiment of a JSON packet checking method of the present invention;
fig. 6 is a schematic block diagram of an embodiment of a JSON packet collating device according to the present invention.
The implementation, functional features and advantages of the present invention will be further described with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, fig. 1 is a schematic structural diagram of a terminal device in a hardware operating environment according to an embodiment of the present invention.
The terminal equipment is configured for checking the consistency of the JSON message, can be a PC, a smart phone or server equipment, and runs a virtual machine.
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, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the terminal device configuration shown in fig. 1 does not constitute a limitation of the device and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include an operating system, a network communication module, a user interface module, and a collation program of JSON messages.
In the terminal device shown in fig. 1, the network interface 1004 is mainly used for connecting a backend server and performing data communication with the backend server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and processor 1001 may be configured to invoke a collation program of a JSON packet stored in memory 1005 and perform operations in the following collation method of the JSON packet.
Based on the hardware structure, the embodiment of the JSON message checking method is provided.
It should be noted that, in the present application, json (Java Script Object notification, JS Object Notation, a lightweight data exchange format, JS is entirely called as Java Script, and is a programming language) messages are widely applied in scenarios such as message passing between API interfaces and between front and back ends of an application, and in particular, for development and testing, it is necessary and frequent to check whether Json messages before and after interface change are consistent, whether returned data of Json messages of the same data source after multiparty processing are consistent, and the like.
Currently, a commonly used JSON packet checking method is to Compare data consistency with a tool such as Beyond company (a text file comparison tool) or based on a simple JSON open source packet. However, these checking methods cannot realize the checking of data consistency under the conditions that the data nesting level of the JSON message is deep, the field is changed, or an unordered data list exists in the JSON message, and the like, so that the efficiency of checking the consistency of the JSON message is low.
In view of the above phenomena, the present invention provides a method for checking a JSON packet, and referring to fig. 2, fig. 2 is a schematic flow chart of a first embodiment of the method for checking a JSON packet according to the present invention, where the method for checking a JSON packet according to the present invention is applied to the above terminal device, and includes:
step S10, obtaining a JSON message to be checked and a preset message check rule, wherein the message check rule is obtained by configuring the JSON message to be checked based on the JSON message to be checked;
it should be noted that, in this embodiment, the preset message collation rule is a rule that is configured and generated in advance based on the JSON message to be collated, and is stored in the corresponding collation rule base, and is used for performing consistency collation on the JSON message to be collated, where the collation rule base may specifically be MySQL (a relational database management system) or SQLite (a light database) maintained in the local storage space by the terminal device.
The terminal equipment acquires the JSON message to be checked which needs to be checked for consistency at present from a database for storing the JSON message, and acquires a message check rule for checking consistency of the JSON message to be checked from a check rule base for storing the message check rule.
Specifically, for example, referring to the application flow shown in fig. 5, assuming that a database storing JSON messages is a specific storage space configured and named as a "JSON declaration library" independently in a local storage space at the terminal, the specific storage space may also be maintained as MySQL or SQLite, and a terminal device writes, in the "JSON declaration library", the JSON messages generated during development, testing, and even running processes, so that the terminal device takes the source messages and the target messages generated before and after a certain interface in the "JSON declaration library" is received as requests for performing consistency check on the source messages and the target messages, respectively, i.e., the source messages and the target messages are taken as JSON messages to be checked, and obtains the JSON messages to be checked from the "JSON declaration library" to prepare for performing subsequent consistency check.
And the terminal equipment acquires the JSON message to be checked from the JSON message library, and synchronously acquires a message checking rule which is generated in advance based on the JSON message to be checked in a checking rule library and is used for checking whether a source message and a target message in the JSON message to be checked are consistent.
Further, in a feasible embodiment, the method for checking the JSON packet of the present invention may further include:
and S50, generating a message checking rule for checking consistency of the JSON message to be checked based on the JSON message configuration to be checked.
After receiving a request for performing consistency check on a JSON message and determining the JSON message to be checked pointed by the request, the terminal equipment immediately configures and generates a message check rule for performing consistency check on the JSON message to be checked based on the JSON message to be checked, and stores the message check rule for calling.
It should be noted that, in this embodiment, after generating, based on the configuration of the JSON packet to be checked, a packet matching rule for performing consistency matching on the JSON packet to be checked, the terminal device may store the packet matching rule in the matching rule base according to the time when the request for performing consistency matching on the JSON packet is received. Therefore, when the terminal device starts to perform consistency check on the JSON message to be checked, the message check rule can be accurately extracted from the check rule base according to the requested time and used for performing consistency check on the JSON message to be checked.
Or after the terminal device configures and generates the message check rule for performing consistency check on the JSON message to be checked, the terminal device can also directly store the message check rule into the check rule base according to the current time, so that when the terminal device immediately starts to perform consistency check on the JSON message to be checked based on a request, the terminal device can extract the latest message check rule from the check rule base according to the current time for performing consistency check on the JSON message to be checked.
It should be noted that, in this embodiment, since a new request is not received after the current time, or a new request is not responded (a terminal device may be set to respond to a next new request after the current request is executed), so that no other packet collation rule is configured and generated after the current time, the latest packet collation rule generated by the current configuration is a rule for performing consistency collation on the JSON packet to be collated.
Further, in a possible embodiment, in step S50, generating, based ON the JSON message configuration to be checked, a message checking rule for performing consistency checking ON the JSON message to be checked may include:
step S501, acquiring a preset message checking requirement, and analyzing a data structure of the JSON message to be checked;
the method comprises the steps that when the terminal equipment determines the JSON message to be checked which needs to be checked for consistency at present, and the message checking rule is configured and generated based on the JSON message to be checked, the message checking requirement for checking consistency of the JSON message to be checked is firstly obtained, and the data structure of the JSON message to be checked is synchronously analyzed.
It should be noted that, in this embodiment, the terminal device may obtain, from the received request for performing consistency check ON the json message to be checked, a message checking requirement for performing consistency check, where the message checking requirement includes but is not limited to: a direct-compared field, a compared array, and an array within the compared array.
Specifically, for example, after the terminal device receives a request for performing consistency comparison on a source message and a target message before and after a certain interface changes, and determines the source message and the target message as JSON messages to be checked together, the terminal device further determines, based on a mature instruction parsing technique, that a message checking requirement for performing consistency checking on the JSON messages to be checked at present is a direct comparison field, a comparison array, or an array in the comparison array from among the request, and the terminal device further parses and determines data structures such as all fields included in each of the source message and the target message based on a mature data structure parsing technique.
And step S502, configuring and generating a message checking rule which corresponds to the data structure and is used for performing consistency checking on the JSON message to be checked according to the message checking requirement.
The terminal equipment acquires a message checking requirement for performing consistency checking on the JSON message to be checked, analyzes a data structure of the JSON message to be checked, and configures and generates a message checking rule corresponding to the data structure according to the message checking requirement, so that the message checking rule can be used for accurately performing consistency checking on the checked JSON message.
Specifically, for example, please refer to the field description in the message matching rule shown in fig. 3, and assume that the terminal device obtains the matching requirement of the message from the request for matching the consistency of the JSON message to be matched: directly comparing fields of a source message and a target message, so as to determine from _ path = source.a.b? And to _ path = target.x.y, and after the terminal device obtains all the fields contained in the source message and the target message by analysis, a message collation rule corresponding to all the fields and capable of being used for accurately collating the source message and the target message is configured as follows: INSERT _ sync _ 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, return) VALUES (' T3_ acc _ INFO _ NEW _02', ' T3_ acc _ INFO _ NEW ', ' VALUE ', ' custustnumber ', ' cure _ NUMBER ', ' N ', ' compare T3 account INFO ' external content ').
Or, assuming that the obtained message check requirement obtained by the terminal device from the request for performing consistency check on the JSON message to be checked is as follows: comparing arrays aiming at a source message and a target message so as to determine that the name of the array needs to be configured in a message checking rule generated by the needed configuration, fields which are not wanted to be compared in the array can be configured in 'sys _ rmb _ compare _ def.align _ field _ from' and 'sys _ rmb _ compare _ def.align _ field', and after the terminal equipment analyzes all the fields contained in the source message and the target message, the message checking rule which corresponds to all the fields and can be used for accurately checking the consistency of the source message and the target message is configured as follows: INSERT _ sys _ check _ def (id, group _ id, component _ type, from _ path, to _ path, check _ first _ only _ if _ LIST, check _ size _ if _ LIST, from _ check _ fields, to _ check _ fields, mark) VALUES ('T3 _ TRANS _ NEW _01', 'T3_ TRANS _ NEW', 'LIST', 'output.txn _ ARRAY', 'TXN _ ARRAY', 'N', 'compare T3 accountinfo').
Or, assuming that the obtained message checking requirement obtained by the terminal device from the request for performing consistency checking on the JSON message to be checked is as follows: comparing arrays in the arrays aiming at a source message and a target message, so as to determine that arrays with different nesting levels need to be divided by using "#" in a message checking rule which needs to be configured and generated, and after a terminal device analyzes and obtains all fields contained in the source message and the target message, configuring and generating a message checking rule which corresponds to all the fields and can be used for accurately checking the consistency of the source message and the target message as follows: INSERT _ sys _ check _ def (id, group _ id, composition _ type, from _ path, to _ path, check _ first _ only _ if _ LIST, check _ size _ if _ LIST, from _ check _ fields, to _ check _ fields, mark) VALUES ('T3 _ acc _ INFO _ NEW _03', 'T3_ acc _ INFO _ NEW', 'LIST _ LIST', 'accountinfo # subAccountInfo', 'ACCOUNT _ INFO _ ack _ INFO', 'N',
'accountBance, accountStatus, acctNo, availableBanace, currencyCode, openChannelId, openDate, productId, subaccountSerialNo', 'Account _ BALANCE, ACCOUNT _ STATUS, ACCT _ NO, AVAILABLE _ BALANCE, CURNCY _ CODE, OPEN _ NNCHAEL _ ID, OPEN _ DATE, PRODUCT _ ID, SUB _ ACCOUNT _ SERIAL _ NO', and 'COMPART 3 subaccountInfo').
In this embodiment, by acquiring a message checking requirement for performing consistency checking on a JSON message to be checked and synchronously analyzing a data structure of the JSON message to be checked, a message checking rule corresponding to the data structure is configured and generated according to the message checking requirement, so that the message checking rule can be used for accurately performing consistency checking on the checked JSON message. Therefore, compared with the traditional mode of carrying out JSON message consistency comparison by adopting a Beyond company tool or based on a simple Json source-opening packet, the method and the device do not need additional development work, can realize complicated, customizable and multi-level JSON message consistency check only by dynamically configuring the corresponding message check rule according to the message check requirement, and further improve the check efficiency.
Step S20, converting the first source message in the JSON message to be checked into a second source message with a Map data structure, and converting the first target message in the JSON message to be checked into a second target message with the Map data structure;
after acquiring the JSON message to be checked which needs to be subjected to consistency check at present, the terminal device further converts a first source message in the JSON message to be checked into a second source message of a Map data structure, and also converts a first target message in the JSON message to be checked into a second target message of the Map data structure.
Specifically, for example, after the terminal device receives a request for consistency check on a source packet and a target packet generated before and after a change of an interface in a "JSON packet library", respectively, so as to use the source packet and the target packet as JSON packets to be checked, and obtain the JSON packets to be checked from the "JSON packet library" to prepare for consistency check, the terminal device uses the source packet as a first source packet to convert the first source packet into a second source packet of a Map data structure, and further uses the target packet as a first target packet to convert the first target packet into a second target packet of the Map data structure, so as to compare values determined conveniently according to the second source packet and the second target packet of the Map data structure.
Further, in a possible embodiment, the Map data structure includes: a general Map data structure and a nested Map data structure, in step S20, the step of "converting the first source packet in the JSON packet to be checked into the second source packet of the Map data structure" may include:
step S201, determining first message data in a common form and/or second message data in a nested form in the first source message;
when the terminal equipment converts a first source message in the JSON message to be checked into a second source message of a Map data structure, first message data in a common form and/or second message data in a nested form are determined in the first source message.
It should be noted that, in this embodiment, the first packet data in the normal form is a K-V form packet content in the JSON packet, and the second packet data in the nested form is a K-List form or a K-List (List) form packet content in the JSON packet.
Step S202, 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 message of the nested Map data structure;
after the terminal device determines the first message data in the common form and/or the second message data in the nested form from the first source message, the terminal device performs conversion respectively for the first message data and/or the second message data, that is, directly converts the first message data into the second source message in the common Map data structure, and/or correspondingly converts the second message data into the second source message in the nested Map data structure.
It should be noted that, in this embodiment, the general Map data structure is WeMap (K, V), and the message of the WeMap (K, V) may be directly obtained based on the Value-taking algorithm WeMap. The nested Map data structure is WeMap (K, list (WeMap ((K1, V1), (K2, V2), \8230 \ 8230;))), where a message of WeMap (K, list (WeMap ((K1, V1), (K2, V2), \ 8230; \ 8230;)) requires a Value-taking algorithm of the corresponding nested hierarchy to obtain a Value of the corresponding nested hierarchy, i.e., obtains a corresponding V1 through wemap.get (k.k 1), obtains a corresponding V2 through wemap.get (k.k 1), and obtains a List (WeMap ((K1, V1), (K2, V2), \\\ 8230;), where V1 and V2 refer to a Value of the corresponding 1 st hierarchy and a Value of the corresponding 2 nd hierarchy, respectively. And by analogy, the extraction of the corresponding Value in any multi-level JSON message can be supported.
Further, in a possible embodiment, in the step S20, the step of "converting the first target packet in the JSON message to be checked into the second target packet of the Map data structure",
step S203, determining third message data in a common form and/or fourth message data in a nested form in the first target message;
when converting a first target message in a JSON message to be checked into a second target message of a Map data structure, the terminal equipment firstly determines third message data in a common form and/or fourth message data in a nested form in the first target message.
Step S204, converting the third packet data into the second target packet of the ordinary Map data structure, and/or converting the fourth packet data into the second target packet of the nested Map data structure.
After the terminal device determines the third message data in the common form and/or the fourth message data in the nested form in the first target message, the terminal device performs conversion respectively for the third message data and/or the fourth message data, that is, directly converts the third message data into the second target message in the common Map data structure, and/or correspondingly converts the fourth message data into the second target message in the nested Map data structure.
Further, in a possible embodiment, in step S204, the step of converting the fourth packet data into the second target packet of the nested Map data structure may include:
step S2041, detecting a Value type corresponding to a healthy Value in each nesting level of the fourth packet data in a loop manner, where the Value type includes: a common Value, a JSON array and a JSON object;
it should be noted that, in this embodiment, when converting the message data in the nested form in the JSON message to be checked into a message in the nested Map data structure, the terminal device circularly executes operations of obtaining a Key Value, obtaining a Value corresponding to the Key, and judging the type of the Value for each level.
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 first acquires a Key Value and then acquires a Value corresponding to the Key for each nested level of the fourth message data, and judges whether the type of the Value is a common Value, a JSON array and a JSON object.
Step S2042, if it is detected that the Value type is the common Value, recording the key Value as a Map data structure to obtain the second target packet.
In the process that the terminal equipment judges the type of the Value aiming at each nesting level of the fourth message data in the nesting form, if the type of the Value is judged to be the common Value, the terminal equipment directly records the key Value of the nesting level as the Map data structure, and thus, after the key values of all the nesting levels are recorded as the Map data structure, the fourth message data is converted into the second target message of the nesting type Map data structure.
Specifically, for example, the terminal device executes, in a loop, for each nesting level in the JSON message to be checked: obtaining a Key Value, obtaining a Value corresponding to the Key, and judging the type of the Value, and when judging that the type of the Value is a JSON Array (Array), further taking the Value as a "List type" to enter the next-level loop processing, and writing a Value in Map data: (Key, tolList (Value)); when the Value is judged to be JSON Object (Object) in type, the Value is further treated as a JSON Object, and a Value: (Key, toWeMap (Value)), so that after the "toWeMap" is called in subsequent processing, the step of "acquiring Key Value" can be returned again to realize recursive resolution of the Value; finally, if the type of the Value is determined to be a common Value, the terminal device may directly write the Value into the Map data when the type is a common Value, that is, the Value is written into the Map data: map (Key, value), thus completing the conversion of the JSON message to be checked into a Map data structure.
It should be noted that, in this embodiment, the function of toList is to parse all Key-values inside the List for the List type Value, and store the Key-values in the Map data structure.
The terminal device determines the type of the Value to be a JSON Array (Array), so as to further take the Value as a "List type" to enter the next level of loop processing, and writes a Value in the Map data: (Key, toList (Value)) then further call the "ToList" to start a re-loop execution for each Value in the List: obtaining a Value and judging the type of the Value, and similarly, when judging the type of the Value, if judging that the type of the Value is a Json array, the terminal device continues to use the Value as a "List type" to enter the next-level loop processing, and the List writes a Value: (toList (Value)), so "toList" can be recursively called to recursively process values inside the List; and when judging that the type of the Value is a Json object, processing the Value as the Json object, and writing a List into a Value: (ToWeMap (Value)), therefore, the ToWeMap can be further called to realize the recursive analysis of the Value and convert all the Value values in the JSON message into values in a Map data structure; finally, when the type of the Value is determined to be a normal Value, the Value is directly written into the List (Value).
In addition, the process of converting the second packet data in the nested form into the second source packet of the nested Map data structure by the terminal device is the same as the process of converting the fourth packet data in the nested form into the second target packet of the nested Map data structure, and is not described herein again.
Step S30, if the MD5 values of the second source message and the second target message are not consistent after comparison, determining a source Value from the second source message according to the message check rule, and determining a target Value from the second target message according to the message check rule;
the terminal equipment converts a first source message and a first target message in the JSON messages to be checked into a second source message and a second target message of a Map data structure, then, the MD5 Value of the whole text is compared with the second source message and the second target message, and when the MD5 values of the second source message and the second target message are different, the source Value is determined in the second source message and the target Value is determined in the second target message for subsequent checking according to the acquired message checking rule for performing consistency checking on the JSON messages to be checked.
It should be noted that, in this embodiment, if the terminal device performs full-text overall MD5 value comparison on the second source packet and the second target packet, and if the MD5 values of the second source packet and the second target packet are the same, the terminal device may directly obtain a packet comparison result that the consistency of the source packet and the target packet in the JSON packet to be checked is successfully checked.
And S40, checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked.
The terminal device determines a source Value in a second source message, determines a target Value in a second target message, compares whether the source Value and the target Value are the same, and correspondingly obtains a message check result that the consistency check of the source message and the target message is successful in the JSON message to be checked when the source Value and the target Value are the same, or correspondingly obtains a message check result that the consistency check of the source message and the target message is failed in the JSON message to be checked when the source Value and the target Value are different.
Specifically, for example, referring to step 2 in an example in which, in an application flow shown in fig. 5, the terminal device performs consistency check on the JSON message to be checked through a checking application (illustrated checking APP), if the terminal device determines that the message checking type is a Value type through the checking application, then, according to a Value path corresponding to the Value type in the message checking rule, a source Value and a target Value corresponding to the same Key are determined from the second source message and the second target message, respectively, and then, the terminal device compares whether the source Value and the target Value are the same, and if the source Value and the target Value are the same through comparison, obtains that the result of the message currently performing consistency check on the JSON message to be checked according to the message checking rule is successful, and conversely, if the source Value and the target Value are not the same, obtains that the result of the message checking is failed, and records a reason of the failure.
Further, in one possible embodiment, the source Value includes: an inner source Value, the destination Value comprising: the inner Value, the step S30, may include:
step S301, determining a first Value path corresponding to a preset Value message check type in the message check rule;
it should be noted that, in this embodiment, the terminal device may specifically obtain the preset Value packet checking type by analyzing the received request for performing consistency checking on the JSON packet to be checked.
When the terminal device determines a source Value and a destination Value from a second source message and a second destination message respectively according to the acquired message check rule, if a Value message check type for consistency check of a JSON message to be checked is acquired, a first Value path corresponding to the Value type and used for extracting an inner layer source Value and an inner layer destination Value is determined in the second source message and the second destination message according to the Value message check type.
Step S302, determining the inner-layer source Value from the second source packet according to the first Value path, and determining the inner-layer destination Value from the second destination packet according to the Value path.
After determining the first Value path from the message checking rule according to the Value message checking type, the terminal device further obtains an inner layer source Value of the innermost layer from the multi-level second source message according to the first Value path, and obtains an inner layer target Value of the innermost layer from the multi-level second target message according to the first Value path.
Specifically, for example, it is assumed that a second source packet of a Map data structure obtained by converting a first source packet in a JSON packet to be checked by a terminal device is: weMap (K, list (WeMap (K1, list) (WeMap ((K2, V2), (K3, V3), \8230;))))). Thus, if the Value message check type is obtained by the terminal device, and the first Value path determined from the message check rule by the Value message check type is: if the Key is k.k1.k2, the terminal device directly sends the message from the second source according to the Key being k.k1.k 2: in WeMap (K, list (WeMap ((K2, V2), (K3, V3), \8230;))))) V2, which acquired the innermost layer, was used as the Value of the inner layer source Value. Similarly, the terminal device may obtain the Value of the inner layer destination Value of the innermost layer from the second destination packet.
Further, step S40 may include:
step S401, comparing the inner layer source Value with the inner layer target Value to obtain a comparison result;
step S402, if the comparison result is that the inner layer source Value is the same as the inner layer target Value, a message checking result that the consistency checking of the JSON message to be checked is successful is obtained.
Specifically, for example, the terminal device follows the first value path: key is k.k1.k2, and from the second source message: in WeMap (K, list (WeMap (K1, list ((K2, V2), (K3, V3), \8230;))))), obtaining V2 of the innermost layer as an inner layer source Value, and, according to the first Value path: the Key is k.k1.K2, the innermost layer destination Value is obtained from the second destination packet having the same Map data structure as the second source packet, then the terminal device compares whether the innermost layer source Value and the innermost layer destination Value are the same, and if the innermost layer source Value and the innermost layer destination Value are the same, the message checking result of the consistency checking of the JSON packet to be checked according to the message checking rule is obtained as success, otherwise, if the source Value and the destination Value are not the same, the message checking result is obtained as failure, and the reason of the failure is recorded.
Further, in another possible embodiment, the source Value includes: a first source field Value, the destination Value comprising: the first destination field Value, in step S30, may further include:
step S303, determining a second value-taking path corresponding to the preset List message check type in the message check rule;
it should be noted that, in this embodiment, the terminal device may specifically obtain the preset List message check type by analyzing the received request for performing consistency check on the JSON message to be checked.
When the terminal device determines a source Value and a target Value from a second source message and a second target message respectively according to the obtained message check rule, if a List message check type for performing consistency check on a JSON message to be checked is obtained, a second Value path corresponding to the List type and used for extracting a first source field Value and a first target field Value is determined in the second source message and the second target message according to the List message check type.
Step S304, determining the Value of the first source field from each piece of source packet data of the second source packet according to the second Value-taking path, and determining the Value of the first destination field from each piece of source packet data of the second destination packet according to the second Value-taking path.
After determining the second Value path from the message checking rule according to the List message checking type, the terminal device further obtains the Value of the first source field of the source message data of each level in each source message data of the multi-level second source message according to the second Value path, and obtains the Value of the first destination field of the source message data of each level in each source message data of the multi-level second destination message according to the second Value path.
Specifically, for example, it is assumed that the second source message of the Map data structure obtained by the terminal device converting the first source message in the JSON message to be checked is K, and WeMap in List form (K, list (WeMap ((K1, V1), (K2, V2), \8230; \8230))). Thus, if the Value message check type is obtained by the terminal device, and the second Value path determined from the message check rule by the List message check type is: if the Key is K, the terminal device directly sends the message from the second source according to the Key as K: in WeMap (K, list ((K1, V1), (K2, V2), \8230;))), the Value of the first source field Value of the source packet data corresponding to the List of the outermost layer is obtained as follows: list (WeMap ((K1, V1), (K2, V2), \8230;), and so on) obtains the first source field Value of the source message data corresponding to all lists at each level. Similarly, the terminal device may obtain the Value of the first destination field of the source packet data of each level from the source packet data of the second destination packet.
Further, step S40 may further include:
step S403, sorting each source message data and each target message data according to the sorting mode corresponding to the List type in the message checking rule;
it should be noted that, in this embodiment, the terminal device may configure an ordering field in the message collation rule based on the received request for performing consistency collation on the JSON message to be collated.
Specifically, for example, after the terminal device obtains the Value of the first source field of the source packet data corresponding to each layer List of the second source packet and the Value of the first destination field of the destination packet data corresponding to each layer List of the second destination packet, the terminal device sorts the plurality of packet data in each layer List according to the sorting fields configured in the packet checking rule, so as to obtain the sorted packet data.
Step S404, checking whether the first data number of each sequenced source message data is consistent with the first data number of each sequenced target message data;
after sequencing each source message data and each target message data, the terminal equipment judges whether the first data number of each sequenced source message data and each sequenced target message data is consistent or not according to a message check rule.
Specifically, for example, after the terminal device sorts the plurality of pieces of message data in each level List according to the sorting fields configured in the message collation rule to obtain the sorted message data, it detects whether a collation rule for the number of data pieces in the List is configured in the message collation rule (assuming that the respective numbers of collation source message data and target message data are the same or the number of collation source message data cannot be less than the number of target message data, etc.), so that, if it is detected that the collation rule is configured in the message collation rule, the number of message data pieces in each level List after sorting the source message data is compared with the number of message data pieces in each level List after sorting the entry mark message data to determine whether the numbers are the same, and if the collation is different, the collation failure is returned, and the failure reason is recorded.
Step S405, if the number of the first data pieces is checked to be consistent, comparing the Value of the first source field with the Value of the first target field;
step S406, when the first source field Value and the first target field Value obtained by comparison are the same, a message checking result that the consistency checking of the JSON message to be checked is successful is obtained.
When the terminal equipment checks that the respective first data numbers of each source message data and each item label message data are consistent after sequencing, further comparing the determined first source field Value with the first target field Value; and when the first source field Value is compared with the first target field Value, correspondingly obtaining a message checking result of successful checking of the consistency of the source message and the target message in the JSON message to be checked.
It should be noted that, in this embodiment, a process of checking, by the terminal device, whether the first source field Value and the first destination field Value are consistent is the same as the process of checking, by the terminal device, whether the source field Value and the destination field Value are consistent, and redundant description is not repeated here. In addition, before checking the first source field Value and the first destination field Value, the terminal device also checks whether the configuration of the first piece of data needs to be checked exists in the message checking rule, and similarly, if the configuration exists but the second source message and the second destination message are checked to be not in accordance with the rule, the result of the message checking is a failure, and the reason of the failure is recorded; the terminal device may check each source packet data or each destination packet data in each layer List one by one according to the field.
Further, in yet another possible embodiment, the source Value includes: a second source field Value, the destination Value comprising: the second destination field Value, in the step S30, may further include:
step S305, determining a third value taking path corresponding to the preset List _ List message checking type in the message checking rule;
it should be noted that, in this embodiment, the terminal device may specifically obtain the preset List _ List message checking type by analyzing the received request for performing consistency checking on the JSON message to be checked.
When the terminal device determines the source Value and the destination Value from the second source message and the second destination message respectively according to the acquired message check rule, if the List _ List message check type for performing consistency check on the JSON message to be checked is acquired, a third Value path corresponding to the List _ List type and used for extracting the second source field Value and the second destination field Value is determined in the second source message and the second destination message according to the List _ List message check type.
Step S306, determining the second source field Value from each source packet data of the second source packet according to the third Value-taking path, and determining the second destination field Value from each entry tag packet data of the second destination packet according to the third Value-taking path.
After determining a third Value path from the message checking rule according to the List _ List message checking type, the terminal device further obtains a second source field Value of each level of source message data from each source message data of the multi-level second source message according to the third Value path, and obtains a second destination field Value of each level of source message data from each source message data of the multi-level second destination message according to the third Value path.
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 K, list (List) form WeMap (K, list (WeMap (K1, list (WeMap ((K2, V2), (K3, V3), \ 8230; \ 8230;)))))))). Thus, if the terminal device obtains the List _ List message check type, and the third value-taking path determined from the message check rule by the List _ List message check type is: and if the Key is K, the terminal equipment directly sends a message from a second source according to the Key: in WeMap (K, list (WeMap ((K1, V1), (K2, V2), \8230; \8230))), the Value of the second source field Value of the source message data corresponding to the List in the outermost layer is obtained as: the Value is a List (K1, list (WeMap ((K2, V2), (K3, V3), \8230;))), and so on, the Value of the second source field Value of the source message data corresponding to all the lists at each level is obtained. Similarly, the terminal device may obtain the Value of the second destination field of the source packet data of each level from the source packet data of the second destination packet.
Further, the step S40 may further include:
step S407, checking second data strips of the source message data and the target message data layer by layer from outside to inside according to a hierarchical sequence;
it should be noted that, in the present embodiment, the hierarchical order is the hierarchical order of the message data in the second source message and the second destination message indicated by each List in the Map data structure, for example, when the second source message is K, a WeMap (K, list) in List (List) form (WeMap (K1, list (WeMap ((K2, V2), (K3, V3), \ 8230; \8230;)))))))), the outermost source message data indicated by the List is: weMap (K, list) (WeMap (K1, list (WeMap ((K2, V2), (K3, V3), \8230;)))), and the source message data of the innermost layer indicated by the List are: weMap ((K2, V2), (K3, V3), \8230;).
Specifically, for example, the terminal device detects whether a check rule for the number of data pieces in the List is configured in the message check rule, and when the check rule is configured in the message check rule, compares the number of the source message data pieces in each level List with the number of the target message data pieces in each level List in sequence according to the level sequence indicated by the List to determine whether the number of the source message data pieces is the same, and if the number of the source message data pieces is different, returns a check failure and records a failure reason.
Step S408, if the second data number is checked to be consistent, comparing the Value of the second source field with the Value of the second target field;
and step S409, obtaining a message checking result which is successful in consistency checking of the JSON message to be checked when the second source field Value and the second target field Value obtained by comparison are the same.
When the terminal equipment checks that the data number of each source message data is consistent with that of each item label message data layer by layer, the terminal equipment further compares the determined second source field Value with the second target field Value; and when the second source field Value is compared with the second target field Value to be consistent, correspondingly obtaining a message checking result of successful checking of the consistency of the source message and the target message in the JSON message to be checked.
It should be noted that, in this embodiment, a process of checking, by the terminal device, whether the second source field Value and the second destination field Value are consistent is the same as the process of checking, by the terminal device, whether the source field Value and the destination field Value are consistent, and redundant description is not repeated here. Furthermore, when the terminal device checks the data in the inner List in the hierarchical order, that is, based on the List (WeMap (K1, list (Map ((K2, V2), (K3, V3), \8230;)))))), the terminal device checks the data in the inner List through the path configured in the message checking rule: and Key is K1, checking is performed to determine that the Value is List (WeMap ((K2, V2), (K3, V3), \8230;), and the checking rule is the checking process of the terminal device when the message checking type is determined to be the List type.
Further, in a possible embodiment, after performing, in the step S40, checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked, the method for checking a JSON message of the present invention may further include:
step S60, recording the message checking result in a data table associated with a preset checking application for outputting, wherein the running mode of the preset checking application is a background running mode; alternatively, the first and second liquid crystal display panels may be,
and step S70, outputting the message checking result through a preset application program interface.
It should be noted that, in this embodiment, as shown in the application flow shown in fig. 5, the terminal device may execute the process of performing consistency check on the JSON message to be checked in the steps in a manner that the check application runs in the background, or the terminal device may also execute the process of performing consistency check on the JSON message to be checked in any service module that is embedded in the terminal device and performs a message check function in a manner that a functional service module is embedded.
After the terminal equipment performs consistency check on the JSON message to be checked in a background running mode through the checking application and obtains a message checking result, the message checking result is directly recorded in a data table associated with the checking application, and the message checking result is output based on the data table.
Specifically, for example, after performing the above-mentioned checking process of the JSON packet to be checked by the checking application based on the background operation mode and obtaining the result of checking the packet by consistency checking, the terminal device writes the packet checking into the field "composition _ status" of the packet table (assumed to be named as sys _ composition _ payload) of the checking application as shown in fig. 4 (when the result of checking the packet is failed, checking abnormal information is written into the field "error _ msg", so that when displaying the packet table, the terminal device can output the result of checking the packet.
It should be noted that, in this embodiment, the same data table associated with the collation application may be stored in MySQL or sqlite as the collation rule library storing the message collation rule or the JSON message library storing the JSON message.
After the consistency of the JSON message to be checked is checked and the message check result is obtained by applying the embedded service module for executing the message check function, the terminal equipment is to obtain the JSON message to be checked and the application program interface started when the message check rule is obtained through the service module and directly feed back the message check result.
Specifically, for example, after the terminal device performs the above-mentioned checking process of the JSON packet to be checked through the service module embedded in the application and obtains the result of checking the packet by consistency, the terminal device obtains the API, which is the application program interface, enabled when the JSON packet to be checked and the packet checking rule are obtained again by using the service module, and directly returns the packet checking (when the result of packet checking is a failure, abnormal information is also checked synchronously through the API).
It should be noted that, in this embodiment, when the terminal device outputs a packet check result for consistency check of the JSON packet to be checked by checking the application packet table or the application program interface of the service module, if the packet check result is a failure, the terminal device may also alarm in synchronization for the JSON packet to be checked not having consistency.
In this embodiment, the terminal device may execute the above-mentioned process of performing consistency check on the JSON message to be checked in the steps in a manner that the check application runs in the background, or the terminal device may execute the above-mentioned process of performing consistency check on the JSON message to be checked in a manner that the function service module is embedded by using the service module, which is embedded in the terminal device and performs the message check function, in any way. Compared with the traditional mode of performing JSON message consistency comparison by adopting a Beyond compact tool or based on a simple Json source-opening packet, the JSON message consistency comparison method and device provided by the invention realize that the JSON message consistency comparison method and device runs in a background in an application mode, directly checks the source JSON message and the target JSON message, or is embedded into other applications, and performs data check through an API (application programming interface), so that the JSON message consistency comparison flexibility is improved.
The method for checking the JSON message comprises the steps that the JSON message to be checked which needs to be checked for consistency at present is obtained from a database for storing the JSON message through terminal equipment, and a message check rule used for checking the consistency of the JSON message to be checked is obtained from a check rule base for storing the message check rule; converting a first source message in the JSON message to be checked into a second source message of a Map data structure, and converting a first target message in the JSON message to be checked into a second target message of the Map data structure; according to the acquired message checking rule for carrying out consistency checking on the JSON message to be checked, determining a source Value in the second source message and determining a target Value in the second target message for subsequent checking; and comparing whether the source Value and the target Value are the same, correspondingly obtaining a message checking result that the consistency of the source message and the target message is successfully checked in the JSON message to be checked when the source Value and the target Value are determined to be the same, or correspondingly obtaining a message checking result that the consistency of the source message and the target message is unsuccessfully checked in the JSON message to be checked when the source Value and the target Value are determined to be different.
Compared with the traditional mode of performing JSON message consistency comparison by adopting a Beyond compact tool or based on a simple Json source-opening packet, the JSON message consistency comparison method based on the JSON message is characterized in that the JSON message is converted into a Map data structure, and the Value is determined based on the Map data structure according to the preconfigured message comparison rule to perform message consistency comparison, so that any field of the JSON message can be conveniently and accurately processed and checked, the situation that the checking cannot be realized in the traditional mode is effectively avoided, and the JSON message consistency comparison efficiency is improved.
In addition, the present invention further provides a device for checking a JSON packet, referring to fig. 6, where the device for checking a JSON packet includes:
the message checking preparation module 10 is configured to obtain a JSON message to be checked and a preset message checking rule, where the message checking rule is obtained by configuring the JSON message to be checked;
a message conversion module 20, configured to convert a first source message in the JSON message to be checked into a second source message of a Map data structure, and convert a first target message in the JSON message to be checked into a second target message of the Map data structure;
a Value determining module 30, configured to determine a source Value from the second source packet according to the packet check rule and determine a destination Value from the second destination packet according to the packet check rule if the MD5 values of the second source packet and the second destination packet obtained by the comparison are inconsistent;
and the checking module 40 is configured to check according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked.
Further, the source Value includes: an inner source Value, the destination Value comprising: the inner-layer destination Value, value determination module 30, includes:
a first path determining unit, configured to determine a first Value path corresponding to a preset Value packet check type in the packet check rule;
a first Value determining unit, configured to determine the inner layer source Value from the second source packet according to the first Value path, and determine the inner layer destination Value from the second destination packet according to the Value path;
a reconciliation module 40 comprising:
the first comparison unit is used for comparing the inner layer source Value with the inner layer target Value to obtain a comparison result;
and the first result determining unit is used for obtaining a message checking result which is successful in consistency checking of the JSON message to be checked if the comparison result is that the inner layer source Value is the same as the inner layer target Value.
Further, the source Value includes: a first source field Value, the destination Value comprising: a first destination field Value, value determination module 30, comprising:
a second path determining unit, configured to determine a second value-taking path corresponding to a preset List message collation type in the message collation rule;
a second Value determining unit, configured to determine the first source field Value from each piece of source packet data of the second source packet according to the second Value path, and determine the first destination field Value from each piece of source packet data of the second destination packet according to the second Value path.
Further, the verification module 40 includes:
a sorting unit, configured to sort each source packet data and each target packet data according to a sorting manner corresponding to the List type in the packet collation rule;
a first checking unit, configured to check whether the respective first data numbers of the sorted source packet data and the sorted target packet data are consistent;
a second comparing unit, configured to compare the Value of the first source field with the Value of the first destination field if the number of the first data pieces is checked to be consistent;
and the second result determining unit is used for obtaining a message checking result which is successful in consistency checking of the JSON message to be checked when the first source field Value and the first target field Value obtained by comparison are the same.
Further, the source Value includes: a second source field Value, the destination Value comprising: a second destination field Value, value determination module 30, comprising:
a third path determining unit, configured to determine a third value-taking path corresponding to a preset List _ List message check type in the message check rule;
a third Value determining unit, configured to determine the second source field Value from each piece of source packet data of the second source packet according to the third Value path, and determine the second destination field Value from each piece of entry marker packet data of the second destination packet according to the third Value path.
Further, the verification module 40 includes:
the second checking unit is used for checking the second data strip number of the source message data and the target message data layer by layer from outside to inside according to the hierarchical sequence;
a third comparing unit, configured to compare the second source field Value with the second destination field Value if the second data number is checked to be consistent;
and the third result determining unit is used for obtaining a message checking result which is successful in consistency checking of the JSON message to be checked when the second source field Value and the second target field Value obtained by comparison are the same.
Further, the apparatus for checking JSON packet of the present invention further includes:
and the generating module is used for acquiring a preset message checking requirement and analyzing the data structure of the JSON message to be checked so as to generate a message checking rule which corresponds to the data structure and is used for performing consistency checking on the JSON message to be checked according to the message checking requirement.
Further, after the checking is performed according to the source Value and the target Value to obtain the message checking result of the JSON message to be checked, the apparatus further includes:
the first output module is used for recording the message checking result in a data table associated with a preset checking application for outputting, wherein the running mode of the preset checking application is a background running mode; alternatively, the first and second electrodes may be,
and the second output module is used for outputting the message checking result through a preset application program interface.
Further, the Map data structure includes: a general type Map data structure and a nested type Map data structure,
the message conversion module 20 is further configured to:
determining first message data in a common form and/or second message data in a nested form in the first source message;
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 message of the nested Map data structure;
the message conversion module 20 is further configured to:
determining third message data in a common form and/or fourth message data in a nested form in the first target message;
and 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 message of the nested Map data structure.
Further, the message conversion module 20 is further configured to:
circularly detecting Value types corresponding to key values in all nesting levels of the fourth message data, wherein the Value types comprise: a common Value, a JSON array and a JSON object;
if the Value type is detected to be the common Value, recording the key Value as a Map data structure to obtain the second target message.
The method executed by each program unit can refer to each embodiment of the JSON message checking method of the present invention, and details are not repeated here.
The invention also provides a device for checking the JSON message, which comprises: the memory, the processor and the checking program of the JSON message stored in the memory and capable of running on the processor, and the method for realizing the checking program of the JSON message when being executed by the processor can refer to each embodiment of the checking method of the JSON message of the invention, and the details are not repeated herein.
The invention also provides a computer storage medium.
The invention stores a check program of the JSON message on a computer storage medium, and the check program of the JSON message realizes the steps of the check method of the JSON message when being executed by a processor.
The method implemented when the checking program of the JSON packet running on the processor is executed may refer to each embodiment of the checking method of the JSON packet of the present invention, and is not described herein again.
The invention also provides a computer program product.
The computer program product comprises a JSON message checking program, and the steps of the JSON message checking method are realized when the JSON message checking program is executed by a processor.
The method implemented when the checking program of the JSON packet running on the processor is executed may refer to each embodiment of the checking method of the JSON packet of the present invention, and is not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of other like elements in a process, method, article, or system comprising the element.
The above-mentioned serial numbers of the embodiments of the present invention are only for description, and do not represent the advantages and disadvantages of the embodiments.
Through the description of the foregoing embodiments, it is clear to those skilled in the art that the method of the foregoing embodiments may be implemented by software plus a necessary general hardware platform, and certainly may also be implemented by hardware, but in many cases, the former is a better implementation. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (8)

1. A JSON message checking method is characterized by comprising the following steps:
acquiring a JSON message to be checked and a preset message checking rule, wherein the message checking rule is obtained by configuring the JSON message to be checked based on the JSON message to be checked;
converting a first source message in the JSON message to be checked into a second source message of a Map data structure, and converting a first target message in the JSON message to be checked into a second target message of the Map data structure;
if the MD5 values of the second source message and the second target message are not consistent after comparison, determining a source Value from the second source message according to the message check rule, and determining a target Value from the second target message according to the message check rule;
checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked;
the source Value values include: a first source field Value, the destination Value comprising: the Value of the first destination field Value is,
the steps of determining a source Value from the second source message according to the message collation rule, and determining a destination Value from the second destination message according to the message collation rule include:
determining a second value taking path corresponding to a preset List message checking type in the message checking rule;
determining the first source field Value from each source message data of the second source message according to the second Value path, and determining the first target field Value from each item label message data of the second target message according to the second Value path;
the step of checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked includes:
sorting each source message data and each target message data according to a sorting mode corresponding to the List message checking type in the message checking rule;
checking whether the first data number of each source message data and each target message data after sequencing is consistent;
if the number of the first data is consistent through checking, comparing the Value of the first source field with the Value of the first target field;
and obtaining a message checking result of successfully performing consistency checking on the JSON message to be checked when the first source field Value and the first target field Value obtained by comparison are the same.
2. The method for checking the JSON packet according to claim 1, wherein the source Value includes: an inner source Value, the destination Value comprising: the Value of the inner-layer destination Value,
the steps of determining a source Value from the second source packet according to the packet collation rule, and determining a destination Value from the second destination packet according to the packet collation rule include:
determining a first Value path corresponding to a preset Value message check type in the message check rule;
determining the inner layer source Value from the second source message according to the first Value path, and determining the inner layer destination Value from the second destination message according to the first Value path;
the step of checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked includes:
comparing the inner layer source Value with the inner layer target Value to obtain a comparison result;
and if the comparison result is that the inner layer source Value is the same as the inner layer target Value, obtaining a message checking result of successfully checking the consistency of the JSON message to be checked.
3. The method for checking JSON packet according to claim 1, wherein the source Value includes: a second source field Value, the destination Value comprising: the Value of the second destination field Value is,
the steps of determining a source Value from the second source packet according to the packet collation rule, and determining a destination Value from the second destination packet according to the packet collation rule include:
determining a third value taking path corresponding to a preset List _ List message check type in the message check rule;
and determining the second source field Value from each source message data of the second source message according to the third Value path, and determining the second destination field Value from each entry target message data of the second destination message according to the third Value path.
4. The method for checking a JSON packet according to claim 3, wherein the step of checking according to the source Value and the destination Value to obtain the packet checking result of the JSON packet to be checked includes:
checking second data strips of the source message data and the target message data layer by layer from outside to inside according to a hierarchical sequence;
if the second data number is consistent through checking, comparing the second source field Value with the second target field Value;
and obtaining a message checking result which is successful in consistency checking of the JSON message to be checked when the second source field Value and the second target field Value obtained by comparison are the same.
5. The method for checking JSON packet according to claim 1, wherein the method further comprises:
and acquiring a preset message checking requirement, analyzing the data structure of the JSON message to be checked, and generating a message checking rule corresponding to the data structure and used for performing consistency checking on the JSON message to be checked according to the message checking requirement.
6. The method for checking JSON packet according to claim 1, wherein the Map data structure includes: a general type Map data structure and a nested type Map data structure,
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 first message data in a common form and/or second message data in a nested form in the first source message;
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 message of the nested Map data structure;
the step of converting the first target message in the JSON message to be checked into a second target message of a Map data structure includes:
determining third message data in a common form and/or fourth message data in a nested form in the first target message;
and 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 message of the nested Map data structure.
7. The method for checking JSON packet according to claim 6, wherein the step of converting the fourth packet data into the second target packet of the nested Map data structure includes:
circularly detecting Value types corresponding to key values in all nesting levels of the fourth message data, wherein the Value types comprise: a common Value, a JSON array and a JSON object;
if the Value type is detected to be the common Value, recording the key Value as a Map data structure to obtain the second target message.
8. A device for checking JSON messages is characterized in that the device for checking JSON messages comprises:
the message checking preparation module is used for acquiring a JSON message to be checked and a preset message checking rule, wherein the message checking rule is obtained by configuring the JSON message to be checked based on the JSON message to be checked;
the message conversion module is used for converting a first source message in the JSON message to be checked into a second source message of a Map data structure and converting a first target message in the JSON message to be checked into a second target message of the Map data structure;
a Value determining module, configured to determine a source Value from the second source packet according to the packet check rule and determine a destination Value from the second destination packet according to the packet check rule if the MD5 values of the second source packet and the second destination packet obtained by the comparison are inconsistent;
the checking module is used for checking according to the source Value and the target Value to obtain a message checking result of the JSON message to be checked;
the source Value values include: a first source field Value, the destination Value comprising: a first destination field Value, value determination module, comprising:
a second path determining unit, configured to determine a second value-taking path corresponding to a preset List message check type in the message check rule;
a second Value determining unit, configured to determine the first source field Value from each piece of source packet data of the second source packet according to the second Value path, and determine the first destination field Value from each piece of entry target packet data of the second destination packet according to the second Value path;
further, the verification module includes:
a sorting unit, configured to sort each source packet data and each target packet data according to a sorting manner corresponding to the List packet collation type in the packet collation rule;
a first checking unit, configured to check whether the respective first data numbers of the sorted source packet data and the sorted target packet data are consistent;
a second comparing unit, configured to compare the Value of the first source field with the Value of the first destination field if the number of the first data pieces is checked to be consistent;
and the second result determining unit is used for obtaining a message checking result which is successful in consistency checking of the JSON message to be checked when the first source field Value and the first target field Value obtained by comparison are the same.
CN202110746878.XA 2021-06-30 2021-06-30 JSON message checking method and JSON message checking device Active CN113489593B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202110746878.XA CN113489593B (en) 2021-06-30 2021-06-30 JSON message checking method and JSON message checking device
PCT/CN2021/139563 WO2023273218A1 (en) 2021-06-30 2021-12-20 Json packet checking method and json packet checking apparatus

Applications Claiming Priority (1)

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

Publications (2)

Publication Number Publication Date
CN113489593A CN113489593A (en) 2021-10-08
CN113489593B true CN113489593B (en) 2022-11-08

Family

ID=77939273

Family Applications (1)

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

Country Status (2)

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

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 (5)

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

Family Cites Families (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
CN110377704B (en) * 2019-07-22 2022-04-22 北京百度网讯科技有限公司 Data consistency detection method and device and computer equipment
US10977234B2 (en) * 2019-08-02 2021-04-13 Timescale, Inc. Combining compressed and uncompressed data at query time for efficient database analytics
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
CN113489593B (en) * 2021-06-30 2022-11-08 深圳前海微众银行股份有限公司 JSON message checking method and JSON message checking device

Patent Citations (5)

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

Also Published As

Publication number Publication date
WO2023273218A1 (en) 2023-01-05
CN113489593A (en) 2021-10-08

Similar Documents

Publication Publication Date Title
CN113489593B (en) JSON message checking method and JSON message checking device
CN110933095A (en) Message parsing method and device
CN112187558B (en) Data verification method and device and electronic equipment
CN113268245A (en) Code analysis method, device and storage medium
CN114238948A (en) Application program detection method and device, electronic equipment and storage medium
CN112769706A (en) Componentized routing method and system
CN111026670B (en) Test case generation method, test case generation device and storage medium
CN115237805A (en) Test case data preparation method and device
CN110764760B (en) Method, apparatus, computer system, and medium for drawing program flow chart
CN111158777A (en) Component calling method and device and computer readable storage medium
CN115964054A (en) Application service deployment method and device
CN116010389A (en) Data verification method, device, equipment and storage medium
CN110266596B (en) Message processing method, device, equipment and computer readable storage medium
CN114527993A (en) Application deployment method, device, equipment and medium
CN113468446A (en) Method, system and equipment for supporting identification of third-party two-dimensional code data
CN113329096A (en) Message transmission method and device, electronic equipment and storage medium
CN114157439A (en) Vulnerability scanning method, computing device and recording medium
CN114564413B (en) Synchronous equipment testing method and device
CN109284097A (en) Realize method, equipment, system and the storage medium of complex data analysis
CN117112654B (en) City data display method, device, computer equipment and storage medium
CN112737872B (en) ARINC664P7 end system cross-network testing system and method
CN113821441B (en) Execution method, device, equipment and storage medium based on document test case
CN117472367B (en) Heterogeneous resource intelligent identification and access method, device, equipment and storage medium
CN107609008A (en) A kind of data importing device and method from relevant database to Kafka based on Apache Sqoop
CN111221719B (en) Automatic test system and test method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant