CN109032886A - Json message comparison method and system - Google Patents
Json message comparison method and system Download PDFInfo
- Publication number
- CN109032886A CN109032886A CN201810646030.8A CN201810646030A CN109032886A CN 109032886 A CN109032886 A CN 109032886A CN 201810646030 A CN201810646030 A CN 201810646030A CN 109032886 A CN109032886 A CN 109032886A
- Authority
- CN
- China
- Prior art keywords
- comparison
- node
- json
- customized
- message
- 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.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3065—Monitoring arrangements determined by the means or processing involved in reporting the monitored data
- G06F11/3072—Monitoring arrangements determined by the means or processing involved in reporting the monitored data where the reporting involves data filtering, e.g. pattern matching, time or event triggered, adaptive or policy-based reporting
- G06F11/3075—Monitoring arrangements determined by the means or processing involved in reporting the monitored data where the reporting involves data filtering, e.g. pattern matching, time or event triggered, adaptive or policy-based reporting the data filtering being achieved in order to maintain consistency among the monitored data, e.g. ensuring that the monitored data belong to the same timeframe, to the same system or component
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The invention discloses a kind of JSON message comparison method and system, JSON message comparison method the following steps are included: S1, configuration need to carry out customized comparison node path and corresponding customized comparison logic;S2, when carrying out JSON message and comparing, the current node that compares of detection is with the presence or absence of the customized comparison logic of configuration, if so, S3 is thened follow the steps, if it is not, thening follow the steps S4;The customized comparison logic of S3, dynamic analysis, and call customized comparison logic that the current comparison node is compared;S4, the current comparison node is compared according to original comparison logic.The present invention realizes the effect that the flexibly customizing specific node it is not necessary to modify original comparison logic compares logic, greatly promotes the flexibility and scalability of comparison method, improves the efficiency of message comparison.
Description
Technical field
It is the present invention relates to a kind of JSON message comparison method and system, in particular to a kind of to support the customized logic that compares
JSON message comparison method and system.
Background technique
A kind of existing JSON (data interchange format of lightweight) message comparison method carries out section by section JSON format message
Point compares, and inconsistent nodename and nodal value is exported, to position the difference of message.It has a disadvantage in that and judges that nodal value is
No consistent logic be it is fixed, this mode can satisfy demand under most of scene, but there are some specific scenes, examples
As nodal value is different but meet certain logical relation is considered consistent, it is undesirable to be carried out as inconsistent information defeated
Out.However existing comparison method can not support this scene under the premise of not modifying former comparison logic, it still can be as different
The information of cause, which is quoted, to be come, and has been upset comparison result, has been needed manually to be judged, has reduced the efficiency of message comparison.
Summary of the invention
The technical problem to be solved by the present invention is to customized in order to overcome JSON message comparison in the prior art that can not support
The defect for comparing logic provides a kind of JSON message comparison method and system.
The present invention is to solve above-mentioned technical problem by following technical proposals:
The present invention provides a kind of JSON message comparison methods, comprising the following steps:
S1, the node path for needing to carry out customized comparison and corresponding customized comparison logic are configured;
S2, when progress JSON message compares, the current node that compares of detection whether there is the customized comparison logic of configuration,
If so, S3 is thened follow the steps, if it is not, thening follow the steps S4;
The customized comparison logic of S3, dynamic analysis, and customized comparison logic is called to carry out the current comparison node
It compares;
S4, the current comparison node is compared according to original comparison logic.
Preferably, including: before step S2
S11, start to compare two JSON messages;
S12, the JSON sequence of message of character string forms is melted into JSON type object and the recurrence comparison since root node.
Preferably, step S2 is specifically included:
Detection is current to be compared in the node path of customized comparison whether node is contained in configuration to the path of root node,
If so, S3 is thened follow the steps, if it is not, thening follow the steps S4.
Preferably, step S4 is specifically included:
S41, judge whether present node is JSON type, if so, all child nodes to present node compare
It is right, then return step S2;If it is not, thening follow the steps S42;
S42, judge whether present node is array type, if so, all daughter elements to current number group node carry out
It compares, then return step S2;If it is not, thening follow the steps S43;
S43, node content is directly compared.
Preferably, the node path configured in step S1 is from the outermost root node of JSON message to customized comparison
The fullpath of node.
The object of the present invention is to provide a kind of JSON message Compare Systems, comprising:
Configuration module needs the node path for carrying out customized comparison and corresponding customized comparison to patrol for configuring
Volume;
Detection module, for detecting the current node that compares when carrying out JSON message and comparing with the presence or absence of the customized of configuration
Logic is compared, if so, the first comparison module is called, if it is not, then calling the second comparison module;
First comparison module is used for the customized comparison logic of dynamic analysis, and calls customized comparison logic to described
The current node that compares is compared;
Second comparison module is for being compared the current comparison node according to original comparison logic.
Preferably, the JSON message Compare System further include:
Message comparison module compares two JSON messages for starting;
Serialization module, for the JSON sequence of message of character string forms to be melted into JSON type object and is opened from root node
Beginning recurrence compares.
Preferably, whether the detection module is contained in configuration to the path of root node for detecting current comparison node
In the node path of customized comparison, if so, the first comparison module is called, if it is not, then calling the second comparison module.
Preferably, second comparison module includes the first judging unit, second judgment unit and direct comparing unit;
First judging unit, for judging whether present node is JSON type, if so, to the institute of present node
There are child nodes to be compared, then calls the detection module;If it is not, then calling the second judgment unit;
The second judgment unit, for judging whether present node is array type, if so, to current number group node
All daughter elements be compared, then call the detection module;If it is not, then calling the direct comparing unit;
The direct comparing unit is for directly comparing node content.
Preferably, the node path of the configuration module configuration is from the outermost root node of JSON message to customized ratio
Pair node fullpath.
The positive effect of the present invention is that: the present invention pass through configure the node path that needs to carry out customized comparison and
Corresponding to compare logical code, original comparison logic executes customized comparison logical code by way of dynamic analysis, thus
Customized comparison logic and original comparison logic have been separated in structure, have been realized it is not necessary to modify original comparison logic the case where
Lower flexibly customizing specific node compares the effect of logic, greatly promotes the flexibility and scalability of comparison method, improves report
The efficiency that text compares.
Detailed description of the invention
Fig. 1 is the flow chart of the JSON message comparison method of present pre-ferred embodiments.
Fig. 2 is the module diagram of the JSON message Compare System of present pre-ferred embodiments.
Specific embodiment
The present invention is further illustrated below by the mode of embodiment, but does not therefore limit the present invention to the reality
It applies among a range.
As shown in Figure 1, JSON message comparison method of the invention specifically includes the following steps:
Step 101 configures the node path for needing to carry out customized comparison and corresponding customized comparison logic;
Step 102, customized comparison of the current comparison node of detection with the presence or absence of configuration when carrying out JSON message and comparing
Logic, if so, 103 are thened follow the steps, if it is not, thening follow the steps 104;
The customized comparison logic of step 103, dynamic analysis, and call customized comparison logic to the current comparison node
It is compared;
Step 104 is compared the current comparison node according to original comparison logic.
Preferably, the present invention is specific further comprising the steps of between step 101 and step 102:
Step 1011 starts to compare two JSON messages;
The JSON sequence of message of character string forms is melted into JSON type object and the recurrence since root node by step 1012
It compares.
And in a step 102, can specifically detect it is current compare node to the path of root node whether be contained in configuration oneself
It defines in the node path compared, if so, 103 are thened follow the steps, if it is not, thening follow the steps 104.
And at step 104, specifically it can further execute following steps:
Step 1041 judges whether present node is JSON type, if so, to all child nodes of present node into
Row compares, then return step 102;If it is not, thening follow the steps 1042;
Step 1042 judges whether present node is array type, if so, to all daughter elements of current number group node
It is compared, then return step 102;If it is not, thening follow the steps 1043;
Step 1043 directly compares node content.
Wherein, the node path configured in step 101 is specially from the outermost root node of JSON message to customized ratio
Pair node fullpath.
The present invention and having in common that for the prior art are all to carry out full node to JSON message to compare, and find node content
It is different then quoted as difference.Difference is to increase the customized configuration for comparing logic, to support under special scenes not
It is same as normally comparing the alignments of logic, this mode realizes the customized original comparison logical separation of comparison logical AND simultaneously
Purpose.
In specific implementation process of the invention, original JSON message, which compares logic, can be used the realization of java language,
JavaScript language realization can be used in customized comparison logic, and bilingual is all very convenient for handling JSON.
Configuration needs to carry out the node of customized comparison and compares logical code accordingly first, is saved in file or data
In library.The node path of configuration is to compare from the outermost root node of JSON message to the customized fullpath for comparing node
Logical code is the JavaScript code for meeting following form:
It is required that stating a function in code, two string arguments are received, return value is Boolean, and function body is any
Customized comparison logic, such as string argument can be converted by JSON.parse () method in JavaScript
It is compared, directly JSON character string can also be analyzed for JSON object, and specific alignments and standard have been
It is complete customized.
The comparison method for comparing the logical AND prior art using the original JSON message that Java language is realized is roughly the same, first
First with the library third party JSON (such as org.JSON) the JSON message unserializings of character string forms at JSON type object,
Then JSON object is compared from root node recurrence, records the current path for comparing node in comparison process, according to working as when comparison
The preceding type for comparing node is tactful to select specifically to compare, and then continues recurrence if it is JSON type and compares its all sub- section
Point then traverses more all array elements if array type, and other types are then basic data type, can directly be compared
Compared with.
With the prior art the difference lies in that configuration determination according to the path for currently comparing node and before whether there is
Customized comparison logic, does not compare according to above-mentioned primitive logic then, otherwise just carries out according to customized comparison logic, specific side
Method are as follows: take out the current corresponding JavaScript of node that compares from file or database and compare logical code, by Java
JavaScript engine parsing call and execute, code is as follows:
ScriptEngine engine=newScriptEngineManager () .getEngineByName ("
nashorn");
engine.eval(selfDefineCompareLogic);
Invocable invocable=(Invocable) engine;
Boolean result=(boolean) invocable.invokeFunction ("
selfDefineCompareFunc", JSONStr1,JSONStr2);
SelfDefineCompareLogic is customized comparison logical code character string in above-mentioned code,
JavaScript engine dynamic analysis calls selfDefineCompareFunc method therein, is passed to current comparison node
Character string JSONStr1, JSONStr2 obtains the return value of Boolean type as method parameter, i.e., under customized comparison logic
The whether equal result of node.
By above-mentioned implementation, accomplishes that original JSON compares the customized separation for comparing logic of logical AND, mentioned significantly
The flexibility and scalability for having risen comparison method improves the efficiency of JSON message comparison.
The present invention also additionally provides a kind of JSON message Compare System, including configuration module 1, detection module 2, first ratio
To module 3, the second comparison module 4;
The configuration module 1, for configuring the node path for needing to carry out customized comparison and corresponding customized ratio
To logic;
The detection module 2, for detecting the current node that compares when carrying out JSON message and comparing with the presence or absence of configuration
Customized comparison logic, if so, the first comparison module 3 is called, if it is not, then calling the second comparison module 4;
First comparison module 3 is used for the customized comparison logic of dynamic analysis, and calls customized comparison logic to institute
The current node that compares is stated to be compared;
Second comparison module 4 is for being compared the current comparison node according to original comparison logic.
Preferably, JSON message Compare System of the invention further includes message comparison module 5 and serialization module 6;Institute
Message comparison module 5 is stated, compares two JSON messages for starting;The serialization module 6, for by character string forms
JSON sequence of message is melted into JSON type object and recurrence compares since root node.
Wherein, whether the detection module is contained in configuration to the path of root node specifically for the current comparison node of detection
Customized comparison node path in, if so, call the first comparison module, if it is not, then calling the second comparison module.
Second comparison module 4 includes the first judging unit 41, second judgment unit 42 and direct comparing unit 43;
First judging unit 41, for judging whether present node is JSON type, if so, to present node
All child nodes are compared, and then call the detection module;If it is not, then calling the second judgment unit 42;
The second judgment unit 42, for judging whether present node is array type, if so, to current array section
All daughter elements of point are compared, and then call the detection module;If it is not, then calling the direct comparing unit 43;
The direct comparing unit 43 is for directly comparing node content.
Wherein, the node path of configuration module configuration is specially from the outermost root node of JSON message to customized
The fullpath of the node of comparison.
Although specific embodiments of the present invention have been described above, it will be appreciated by those of skill in the art that this is only
For example, protection scope of the present invention is to be defined by the appended claims.Those skilled in the art without departing substantially from
Under the premise of the principle and substance of the present invention, many changes and modifications may be made, but these change and
Modification each falls within protection scope of the present invention.
Claims (10)
1. a kind of JSON message comparison method, which comprises the following steps:
S1, the node path for needing to carry out customized comparison and corresponding customized comparison logic are configured;
S2, when carrying out JSON message and comparing, detection currently compares node with the presence or absence of the customized comparison logic of configuration, if so,
S3 is thened follow the steps, if it is not, thening follow the steps S4;
The customized comparison logic of S3, dynamic analysis, and call customized comparison logic that the current comparison node is compared;
S4, the current comparison node is compared according to original comparison logic.
2. JSON message comparison method as described in claim 1, which is characterized in that include: before step S2
S11, start to compare two JSON messages;
S12, the JSON sequence of message of character string forms is melted into JSON type object and the recurrence comparison since root node.
3. JSON message comparison method as claimed in claim 2, which is characterized in that step S2 is specifically included:
Detection is current to be compared in the node path of customized comparison whether node is contained in configuration to the path of root node, if
It is to then follow the steps S3, if it is not, thening follow the steps S4.
4. JSON message comparison method as described in claim 1, which is characterized in that step S4 is specifically included:
S41, judge whether present node is JSON type, if so, all child nodes to present node are compared, so
Return step S2 afterwards;If it is not, thening follow the steps S42;
S42, judge whether present node is array type, if so, all daughter elements of current number group node are compared,
Then return step S2;If it is not, thening follow the steps S43;
S43, node content is directly compared.
5. JSON message comparison method as described in claim 1, which is characterized in that the node path configured in step S1 be from
The outermost root node of JSON message to customized comparison node fullpath.
6. a kind of JSON message Compare System characterized by comprising
Configuration module, for configuring the node path for needing to carry out customized comparison and corresponding customized comparison logic;
Detection module, for detection currently customized comparison of the comparison node with the presence or absence of configuration when carrying out JSON message and comparing
Logic, if so, the first comparison module is called, if it is not, then calling the second comparison module;
First comparison module is used for the customized comparison logic of dynamic analysis, and calls customized comparison logic to described current
Node is compared to be compared;
Second comparison module is for being compared the current comparison node according to original comparison logic.
7. JSON message Compare System as claimed in claim 6, which is characterized in that the JSON message Compare System also wraps
It includes:
Message comparison module compares two JSON messages for starting;
Serialization module, for the JSON sequence of message of character string forms to be melted into JSON type object and is passed since root node
Return comparison.
8. JSON message Compare System as claimed in claim 7, which is characterized in that the detection module is for detecting current ratio
Whether the path of node to root node is contained in the node path of customized comparison of configuration, if so, calling the first ratio
To module, if it is not, then calling the second comparison module.
9. JSON message Compare System as claimed in claim 6, which is characterized in that second comparison module is sentenced including first
Disconnected unit, second judgment unit and direct comparing unit;
First judging unit, for judging whether present node is JSON type, if so, to all children of present node
Child node is compared, and then calls the detection module;If it is not, then calling the second judgment unit;
The second judgment unit, for judging whether present node is array type, if so, to the institute of current number group node
There is daughter element to be compared, then calls the detection module;If it is not, then calling the direct comparing unit;
The direct comparing unit is for directly comparing node content.
10. JSON message Compare System as claimed in claim 6, which is characterized in that the node road of the configuration module configuration
Diameter is the fullpath of the node from the outermost root node of JSON message to customized comparison.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810646030.8A CN109032886A (en) | 2018-06-21 | 2018-06-21 | Json message comparison method and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810646030.8A CN109032886A (en) | 2018-06-21 | 2018-06-21 | Json message comparison method and system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN109032886A true CN109032886A (en) | 2018-12-18 |
Family
ID=64610373
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810646030.8A Pending CN109032886A (en) | 2018-06-21 | 2018-06-21 | Json message comparison method and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109032886A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111090788A (en) * | 2019-12-03 | 2020-05-01 | 广州品唯软件有限公司 | Json file comparison method and device, storage medium and computer equipment |
Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101908985A (en) * | 2010-08-05 | 2010-12-08 | 中兴通讯股份有限公司 | Message checking method and device |
US20140156689A1 (en) * | 2012-12-05 | 2014-06-05 | The Mathworks, Inc. | Mechanism for comparison of disparate data in data structures |
CN105278946A (en) * | 2015-06-12 | 2016-01-27 | 浙江大学 | RESTful API visualization method |
CN105302601A (en) * | 2015-10-22 | 2016-02-03 | 四川长虹电器股份有限公司 | System and method for software upgrade server |
CN107347048A (en) * | 2016-05-04 | 2017-11-14 | 北京京东尚科信息技术有限公司 | The method, apparatus and system of data check |
CN107733894A (en) * | 2017-10-19 | 2018-02-23 | 携程旅游网络技术(上海)有限公司 | Comparison method, system, equipment and the storage medium of logic interfacing message |
CN108021952A (en) * | 2017-12-29 | 2018-05-11 | 广州品唯软件有限公司 | A kind of rich text control methods and device |
CN108132880A (en) * | 2017-12-21 | 2018-06-08 | 武汉斑马快跑科技有限公司 | A kind of parameter verification method and device |
-
2018
- 2018-06-21 CN CN201810646030.8A patent/CN109032886A/en active Pending
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101908985A (en) * | 2010-08-05 | 2010-12-08 | 中兴通讯股份有限公司 | Message checking method and device |
US20140156689A1 (en) * | 2012-12-05 | 2014-06-05 | The Mathworks, Inc. | Mechanism for comparison of disparate data in data structures |
CN105278946A (en) * | 2015-06-12 | 2016-01-27 | 浙江大学 | RESTful API visualization method |
CN105302601A (en) * | 2015-10-22 | 2016-02-03 | 四川长虹电器股份有限公司 | System and method for software upgrade server |
CN107347048A (en) * | 2016-05-04 | 2017-11-14 | 北京京东尚科信息技术有限公司 | The method, apparatus and system of data check |
CN107733894A (en) * | 2017-10-19 | 2018-02-23 | 携程旅游网络技术(上海)有限公司 | Comparison method, system, equipment and the storage medium of logic interfacing message |
CN108132880A (en) * | 2017-12-21 | 2018-06-08 | 武汉斑马快跑科技有限公司 | A kind of parameter verification method and device |
CN108021952A (en) * | 2017-12-29 | 2018-05-11 | 广州品唯软件有限公司 | A kind of rich text control methods and device |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111090788A (en) * | 2019-12-03 | 2020-05-01 | 广州品唯软件有限公司 | Json file comparison method and device, storage medium and computer equipment |
CN111090788B (en) * | 2019-12-03 | 2023-10-13 | 广州品唯软件有限公司 | json file comparison method and device, storage medium and computer equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107562556B (en) | Failure recovery method, recovery device and storage medium | |
CN109558202A (en) | Original list development approach, device, equipment and storage medium based on small routine | |
US11354325B2 (en) | Methods and apparatus for a multi-graph search and merge engine | |
CN110175027A (en) | A kind of method and apparatus for developing business function | |
CN106326017A (en) | Realization system for call chain based on Annotation application | |
CN110535928B (en) | Event pushing method for JAVA intelligent contract of block chain | |
CN115480753A (en) | Application integration system and corresponding computer device and storage medium | |
CN110781180A (en) | Data screening method and data screening device | |
CN106373571A (en) | Voice control method and device | |
CN109032886A (en) | Json message comparison method and system | |
CN104866764A (en) | Object reference graph-based Android cellphone malicious software detection method | |
CN107291938B (en) | Order inquiry system and method | |
CN103593239B (en) | The method and device of application process command process in LINUX system | |
CN106101359A (en) | The display packing of address list information and device | |
CN117389647A (en) | Plug-in generation method, application development method, device, equipment and medium | |
CN110457212B (en) | Test modeling and test case automatic generation method based on complex system | |
CN115809056B (en) | Component multiplexing implementation method and device, terminal equipment and readable storage medium | |
CN116226256A (en) | ETL flow visualization method, device, equipment and storage medium | |
CN115292065A (en) | Event confirmation method, system and device based on stream architecture | |
WO2019024522A1 (en) | Method, device and system for synchronous communication between title bar and pop-up bar, and storage medium | |
CN108737522B (en) | Message processing method, device and system | |
CN112422349A (en) | Network management system, method, equipment and medium for NFV | |
CN109816005A (en) | Application program trade classification method, storage medium and terminal based on CNN | |
CN115982285B (en) | Data processing method, apparatus and computer readable storage medium | |
CN109151557A (en) | Video creation method and relevant apparatus |
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 | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20181218 |
|
RJ01 | Rejection of invention patent application after publication |