Efficient JSON file format and content verification method

文档序号:1113330 发布日期:2020-09-29 浏览:17次 中文

阅读说明:本技术 一种高效json文件格式及内容验证方法 (Efficient JSON file format and content verification method ) 是由 左劼 段磊 何邦君 谢贵才 陈子豪 于 2020-06-20 设计创作,主要内容包括:本发明公开了一种高效JSON文件格式及内容验证方法,包含构建模板树、读取文档、解析键值对、将解析后的结果与结构树匹配四个部分;相对于现有方式来讲,本发明具有以下优点及有益效果:JSON文档的验证是数据处理中的一个关键步骤。EvsJSON是一种新颖而高效的JSON文档验证方法,现有的方法能够检验JSON文档的结构及内容,但仅限于完整的文档,无法检验拆分后的多个文档;而本发明对应的JSON格式与内容验证算法,不仅在验证速度上超越现有方法,而且能够对拆分文档进行验证,克服了现有方法所遇到的困难。(The invention discloses a high-efficiency JSON file format and content verification method, which comprises four parts of constructing a template tree, reading a document, analyzing key value pairs and matching the analyzed result with a structure tree; compared with the prior art, the invention has the following advantages and beneficial effects: verification of JSON documents is a key step in data processing. EvsJSON is a novel and efficient JSON document verification method, the existing method can be used for detecting the structure and the content of a JSON document, but is limited to a complete document, and a plurality of split documents cannot be detected; the JSON format and content verification algorithm corresponding to the invention not only surpasses the existing method in verification speed, but also can verify the split document, thus overcoming the difficulties encountered by the existing method.)

1. A high-efficient JSON file format and content verification method, construct three parts of customer end, server and database first while implementing; a user inputs form information through a client, then the form information is transmitted to a server, the server realizes verification, and then a verified document is stored in a database; it is characterized in that; the server realizes verification in the following way, and comprises the following four execution parts, wherein each part is specifically executed as follows:

step 1, building a tree; the JSON template is predefined, contains a data type of a collection of keys and values corresponding to each key, and organizes all keys in a particular nested structure; converting the template into a tree structure named as a JSON template tree according to the nested structure of the template, wherein each node represents a key value pair in the JSON template, and each layer in the tree corresponds to one layer in the nested structure of the JSON template;

step 2, reading a document; if the document is too long, splitting a complete JSON document into a plurality of JSON documents; in this step, the JSON document is read by a reader by means of stream data reading, and a specific end symbol (e.g., EOF) is added at the end of each complete document to check the integrity of each document; documents separated from the large documents can be combined into original documents finally;

step 3, resolving the key value pair; the node list is created based on the template tree, stores the information of each node and the father node and the child node of each node, and obtains a hollow node list L containing all tree nodes through the traversal of the front sequence; analyzing and extracting a value corresponding to each node from the document according to the list; storing the information of all key value pairs in the JSON template in a node list;

step 4, matching the analyzed result with a template tree; at this stage, each JSON document will be checked by three conditions, if any is satisfied, and treated as an invalid document:

(1) any key in L does not appear in the JSON document;

(2) the data type of the value corresponding to the key is incorrect;

(3) the structure of the keys in the JSON document does not conform to the sequence of L;

in the verification process, each node is taken out from the L, and if the node and all child nodes thereof are verified to be valid, the node is deleted from the list, so that a large amount of storage space can be saved when large-scale documents are processed; in addition, once a certain node fails to be verified, the document is judged to be an invalid document, and the rest nodes are not checked, so that the verification efficiency is improved; the method is able to find all unmatched nodes if required.

Technical Field

The invention relates to the related fields of data analysis, file format and content verification, in particular to a high-efficiency JSON file format and content verification method.

Background

JSON is well known to be one of the most popular data publishing and interchange formats. In an actual application program scene, due to the limitation of the length of a database field, if a JSON document is too long, the JSON document can only be divided into a plurality of documents and then stored in the database. In this case, verification of the integrity and accuracy of the document is required.

However, JSON is a lightweight and easy-to-use semi-structured model that can flexibly organize and record data such as arrays, and is therefore often used to exchange data. For example, from a client to a database, the general transmission of JSON data over a C/S system is shown in fig. 1. First, the user enters data into the form. The client then receives the data and encapsulates it into a JSON format (i.e., a JSON document). All documents must be validated before being stored in the database. However, due to limitations in the length of fields in the database, long documents can be divided into multiple documents, which presents challenges to data validation.

The existing JSON toolkit comprises two stages when a JSON format is verified, a JSON document and a predefined JSON mode are analyzed, and a corresponding JSON object and a mode object are obtained respectively. Through a predefined JSON schema, the structure of a JSON document can be restricted and checked for integrity. The format of the JSON document can be verified by comparing the JSON object to the schema object. However, the toolkit described above cannot verify multiple JSON documents separated from one long JSON document.

Disclosure of Invention

Therefore, in order to solve the above-mentioned deficiencies, the present invention provides an efficient JSON file format and content verification method; the method not only exceeds the prior method in verification speed, but also can verify the split document, and overcomes the difficulties encountered by the prior method.

The invention is realized in this way, construct a high-efficient JSON file format and content verification method, construct three parts of customer end, server and database first while implementing; a user inputs form information through a client, then the form information is transmitted to a server, the server realizes verification, and then a verified document is stored in a database; it is characterized in that; the server realizes verification in the following way, and comprises the following four execution parts, wherein each part is specifically executed as follows:

step 1, building a tree; the JSON template is predefined and contains a set of data types of values for the keys corresponding to each key, and organizes all keys in a particular nested structure; converting the template into a tree structure named as a JSON template tree according to the nested structure of the template, wherein each node represents a key value pair in the JSON template, and each layer in the tree corresponds to one layer in the nested structure of the JSON template;

step 2, reading a document; if the document is too long, a complete JSON document must be split into multiple JSON documents. In this step, the JSON document is read by means of stream data read-in using a reader, and a specific end symbol (e.g., EOF) is added to the end of each complete document, thereby checking the integrity of each document. Documents separated from large documents can be finally merged into the original document.

Step 3, resolving the key value pair; the node list is created based on the template tree, stores the information of each node and the father node and the child node of each node, and obtains a hollow node list L containing all tree nodes through the traversal of the front sequence; analyzing and extracting a value corresponding to each node from the document according to the list; storing the information of all key value pairs in the JSON template in a node list;

step 4, matching the analyzed result with a template tree; at this stage, each JSON document will be checked by three conditions, if any is satisfied, and treated as an invalid document:

(1) any key in L does not appear in the JSON document;

(2) the data type of the value corresponding to the key is incorrect;

(3) the structure of the keys in the JSON document does not conform to the sequence of L;

in the verification process, each node is taken out from L, and if the node and all child nodes thereof are verified to be valid, the node is deleted from the list, so that a large amount of storage space can be saved when large-scale documents are processed. In addition, once a certain node fails to be verified, the document is judged to be an invalid document, and the rest nodes are not checked, so that the verification efficiency is improved. The method is able to find all unmatched nodes if required.

The invention has the following advantages: the verification of the JSON document is a key step in data processing; in this document, EvsJSON is introduced, which is a novel and efficient method of JSON document verification, particularly for content-coherent JSON documents that are separated from long documents. Experiments on an actual data set show that the EvsJSON is superior to other commonly used JSON document verification methods in efficiency.

In addition, in real life, many websites or platforms provide information entry or upload functions, and particularly, in some fields (such as biological information, materials and the like), a large amount of experimental data needs to be uploaded through a professional platform, and the data is converted into a JSON format and then is finally stored in a database through transmission of a server. Meanwhile, the database has a limit on the length of the storage field, and if the data stored in a single time is too large, the data needs to be split and then stored in the database respectively. To ensure the quality of the data stored, the uploaded data needs to be checked before being stored in the database. The existing method can test the structure and content of the JSON document, but is only limited to a complete document, and can not test a plurality of split documents. The invention is a brand-new JSON format and content verification algorithm, which not only surpasses the prior method in verification speed, but also can verify the split document and overcome the difficulties encountered by the prior method.

Drawings

FIG. 1 is a schematic diagram of JSON data transmitted from a client to a database;

fig. 2 is a schematic view of a structural framework to which the present invention relates.

Detailed Description

The present invention will be described in detail with reference to fig. 1-2, and the technical solutions in the embodiments of the present invention will be clearly and completely described, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

The invention provides a high-efficiency JSON file format and a content verification method by improving, wherein the framework of EvsJSON is shown in figure 2 (a); EvsJSON contains four parts, each of which is performed in detail as follows:

step 1, building a tree; the JSON template is predefined and contains a set of data types of values for the keys corresponding to each key, and organizes all keys in a particular nested structure; converting the template into a tree structure named as a JSON template tree according to the nested structure of the template, wherein each node represents a key value pair in the JSON template, and each layer in the tree corresponds to one layer in the nested structure of the JSON template; fig. 2(b) shows a JSON template tree based on the JSON template in fig. 1.

Step 2, reading a document; if the document is too long, a complete JSON document must be split into multiple JSON documents. In this step, the JSON document is read by means of stream data read-in using a reader, and a specific end symbol (e.g., EOF) is added to the end of each complete document, thereby checking the integrity of each document. Documents separated from large documents can be finally merged into the original document.

Step 3, resolving the key value pair; the node list is created based on the template tree, stores the information of each node and the father node and the child node of each node, and obtains a hollow node list L containing all tree nodes through the traversal of the front sequence; analyzing and extracting a value corresponding to each node from the document according to the list; storing the information of all key value pairs in the JSON template in a node list; the node list shown in fig. 2(c) is obtained by pre-ordering the JSON template tree in fig. 2 (b).

Step 4, matching the analyzed result with a template tree; at this stage, each JSON document will be checked for invalidity if any condition is met by: (1) any key in L does not appear in the JSON document; (2) the data type of the value corresponding to the key is incorrect; (3) the structure of the keys in the JSON document does not conform to the sequence of L; in the verification process, each node is taken out from L, and if the node and all child nodes thereof are verified to be valid, the node is deleted from the list, so that a large amount of storage space can be saved when large-scale documents are processed. In addition, once a certain node fails to be verified, the document is judged to be an invalid document, and the rest nodes are not checked, so that the verification efficiency is improved. The method is able to find all unmatched nodes if required.

The invention has the advantages and beneficial effects that: verification of JSON documents is a key step in data processing. In this document, EvsJSON is introduced, which is a novel and efficient method of JSON document verification, particularly JSON documents that are separated from long documents. Experiments on an actual data set show that the EvsJSON is superior to other commonly used JSON document verification methods in efficiency.

When the efficient JSON file format and content verification method is implemented, a client, a server and a database are constructed firstly, so that a corresponding system platform is formed; the user inputs form information through the client and then transmits the form information to the server, the server realizes verification through the steps, and then the verified document is stored in the database.

Application scenarios: in real life, a plurality of websites or platforms provide information input or upload functions, particularly, in some fields (such as biological information, materials and the like), a large amount of experimental data needs to be uploaded through a professional platform, and the data is converted into a JSON format and then is finally stored in a database through transmission of a server. Meanwhile, the database has a limit on the length of the storage field, and if the data stored in a single time is too large, the data needs to be split and then stored in the database respectively. To ensure the quality of the data stored, the uploaded data needs to be checked before being stored in the database. The existing method can test the structure and content of the JSON document, but is only limited to a complete document, and can not test a plurality of split documents. The invention is a brand-new JSON format and content verification algorithm, which not only surpasses the prior method in verification speed, but also can verify the split document and overcome the difficulties encountered by the prior method.

The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

6页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种数据处理方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!