Method and device for parsing JSON data

By parsing JSON data token by token and skipping irrelevant data according to query requests, the memory waste and inefficiency problems caused by DOM parsing are solved, and efficient parsing JSON data is achieved and database performance is improved.

CN113296782BActive Publication Date: 2024-12-13ALIBABA CLOUD COMPUTING CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202110189624.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-19
Publication Date
2024-12-13
Estimated Expiration
2041-02-19

AI Technical Summary

Technical Problem

The existing technology adopts the DOM parsing style when analyzing JSON data, which leads to a lot of memory waste and inefficiency, making it difficult to efficiently parse JSON data, affecting database performance.

Method used

The method of parsing JSON data by token is adopted, and the information of the query request is used to determine whether the currently parsed token and the remaining unparsed part exists if the required data exists. The parsing of irrelevant data is skipped and the parsing is terminated early, avoiding the construction of a complete Document Object Tree.

Benefits of technology

It greatly reduces the time-consuming and time-consuming of JSON data, improves parsing efficiency, achieves the purpose of efficient parsing JSON data, and improves database performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113296782B_ABST
    Figure CN113296782B_ABST
Patent Text Reader

Abstract

The embodiments of the present specification provide a method and device for parsing JSON data, wherein the method includes: when parsing JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request based on the information specified by the query request; if the currently parsed token does not contain the data required by the query request, skipping the parsing of the value of the currently parsed token; and ending the parsing of the JSON data if the remaining unparsed portion of the JSON data does not contain the data required by the query request.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification relate to the field of computer technology, and more particularly to a method for parsing JSON data. One or more embodiments of this specification also relate to an apparatus for parsing JSON data, a computing device, and a computer-readable storage medium. Background Art

[0002] To meet the increasing demand for federated analysis, some databases have introduced support for external data sources. Among external data sources, JSON data mainly exists in the form of jsonline. Jsonline is a data format with tokens as basic components.

[0003] When querying JSON data, you need to use a JSON data parser to parse the JSON data. Currently, the DOM parsing style is generally adopted, that is, first parse the JSON data completely, including all tokens and corresponding values, and then construct a Document Object Tree in memory. However, DOM parsing wastes a lot of memory and is relatively inefficient. Therefore, how to parse JSON data efficiently has become the key to improving database performance. Summary of the invention

[0004] In view of this, the present specification provides a method for parsing JSON data. One or more embodiments of the present specification also relate to a device for parsing JSON data, a computing device, and a computer-readable storage medium to solve the technical defects existing in the prior art.

[0005] According to a first aspect of an embodiment of the present specification, a method for parsing JSON data is provided, comprising: when parsing JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain data required by the query request based on information specified by a query request; if the currently parsed token does not contain the data required by the query request, skipping parsing of the value of the currently parsed token; and ending parsing of the JSON data if the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0006] Optionally, the JSON data corresponds to data in a table in a database; when parsing the JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request according to the information specified in the query request includes: when parsing the JSON data token by token, judging whether the currently parsed token corresponds to the column specified in the query request; if not, determining that the currently parsed token does not contain the data required by the query request; if corresponding, parsing to obtain the value of the token, and judging whether the value of the currently parsed token needs to be obtained by the query request according to the query conditions specified in the query request; if not, determining that the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0007] Optionally, when parsing the JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request based on the information specified by the query request includes: when parsing the JSON data token by token, if the value of the currently parsed token needs to be obtained by the query request, obtaining the value of the token; judging whether all values ​​required by the query request have been obtained; and if so, determining that the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0008] Optionally, when parsing JSON data token by token, judging whether the currently parsed token does not contain the data required by the query request based on the information specified in the query request includes: when parsing JSON data token by token, judging whether the currently parsed token belongs to the token type corresponding to the information based on the information specified in the query request; if not, determining that the currently parsed token does not contain the data required by the query request.

[0009] Optionally, when parsing JSON data token by token, judging whether the currently parsed token belongs to the token type corresponding to the information according to the information specified in the query request includes: when parsing JSON data token by token, judging whether the currently parsed token belongs to an array type or an object type token according to the column specified in the query request.

[0010] Optionally, determining whether the currently parsed token corresponds to the column specified in the query request includes: if the currently parsed token is an array type token, obtaining the subscript of the array corresponding to the token as the column number; and determining whether the column number is the column number specified in the query request.

[0011] Optionally, the determination of whether the currently parsed token corresponds to the column specified in the query request includes: if the currently parsed token is an object type token, obtaining the object name of the token; using the object name of the token as the column name, and determining whether the column name has a corresponding column in the data table; if so, obtaining the corresponding column number; and determining whether the column number is the column number specified in the query request.

[0012] Optionally, the step of determining whether the currently parsed token corresponds to the column specified by the query request, and the step of determining whether the value of the currently parsed token needs to be obtained by the query request based on the query conditions specified in the query request, are executed by requesting an external module through a predefined interface.

[0013] According to a second aspect of the embodiments of this specification, there is provided a device for parsing JSON data, comprising: a parsing judgment module, configured to judge whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request when parsing the JSON data token by token, according to the information specified by the query request. A value parsing skip module, configured to skip parsing the value of the currently parsed token if the currently parsed token does not contain the data required by the query request. A parsing end module, configured to end parsing of the JSON data if the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0014] According to a third aspect of the embodiments of this specification, a computing device is provided, including: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions: when parsing JSON data token by token, based on the information specified by the query request, determine whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request; if the currently parsed token does not contain the data required by the query request, skip parsing the value of the currently parsed token; if the remaining unparsed portion of the JSON data does not contain the data required by the query request, end parsing of the JSON data.

[0015] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores computer instructions, and when the computer instructions are executed by a processor, the steps of the method for parsing JSON data described in any embodiment of this specification are implemented.

[0016] An embodiment of the present specification provides a method for parsing JSON data. When parsing JSON data token by token, the method determines whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request based on the information specified by the query request. If the currently parsed token does not contain the data required by the query request, parsing of the value of the currently parsed token is skipped. If the remaining unparsed portion of the JSON data does not contain the data required by the query request, parsing of the JSON data is terminated. Thus, the method provided in the embodiment of the present specification parses token by token and skips parsing of irrelevant data based on the information of the query request, thereby avoiding constructing a complete Document Object Tree in the memory and terminating the parsing of the JSON data early if feasible, thereby significantly reducing the time consumption of parsing the JSON data and achieving the purpose of efficiently parsing the JSON data. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 is a flowchart of a method for parsing JSON data provided by an embodiment of this specification;

[0018] Figure 2 This is a schematic diagram of the state flow of a JSON data parser provided by an embodiment of this specification;

[0019] Figure 3 This is a schematic diagram of the structure of a device for parsing JSON data provided by an embodiment of this specification;

[0020] Figure 4 is a structural diagram of a device for parsing JSON data provided by another embodiment of the present specification;

[0021] Figure 5 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION

[0022] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.

[0023] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.

[0024] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0025] First, the terms involved in one or more embodiments of this specification are explained.

[0026] Token, a concept commonly used in lexical analysis, is the most basic component of JSON data.

[0027] In this specification, a method for parsing JSON data is provided. This specification also relates to an apparatus for parsing JSON data, a computing device, and a computer-readable storage medium, which are described in detail one by one in the following embodiments.

[0028] Figure 1 A flowchart of a method for parsing JSON data provided according to an embodiment of the present specification is shown, including steps 102 to 106.

[0029] Step 102: When parsing the JSON data token by token, it is determined, based on the information specified by the query request, whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0030] Step 104: If the currently parsed token does not contain the data required by the query request, the parsing of the value of the currently parsed token is skipped.

[0031] Step 106: If the remaining unparsed portion of the JSON data does not contain the data required by the query request, the parsing of the JSON data is terminated.

[0032] It can be seen that the method provided in the embodiment of this specification parses token by token, skips the parsing of irrelevant data according to the information of the query request, avoids constructing a complete Document Object Tree in the memory, and terminates the parsing of JSON data early when feasible, thereby greatly reducing the time consumption of parsing JSON data and achieving the purpose of efficiently parsing JSON data. For example, the JSON data parser implemented by the method provided in the embodiment of this specification can be applied to the OLAP (online analytical processing) scenario to accelerate the parsing of JSON data and thus improve the performance of OLAP.

[0033] In the embodiment of this specification, ending the parsing of JSON data means terminating the parsing of a string of input JSON data in advance, that is, not parsing the remaining content of this string of JSON data, and if there is a next string of JSON data, parsing the next string of JSON data can be started. Skipping the parsing of the value of the currently parsed token means that the parsing of the value of the currently parsed token can be skipped, and if there is a next token in this string of JSON data, parsing of the next token can be entered.

[0034] It should be noted that in the method provided in the embodiments of this specification, whether to skip the parsing of the token value and / or end the parsing early is determined based on the information specified in the query request. The specific implementation method can be determined in combination with the way JSON data is used in actual application scenarios, and the embodiments of this specification do not limit this.

[0035] For example, since there is no need to continue parsing the JSON data when all the values ​​required by the query request have been obtained, in one or more embodiments of the present specification, when parsing the JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request based on the information specified by the query request may include: if the value of the currently parsed token needs to be obtained by the query request, obtaining the value of the token; judging whether all the values ​​required by the query request have been obtained; and if so, determining that the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0036] For another example, in an application scenario where JSON data is introduced into a database, the JSON data corresponds to the data of a table in the database. For example, several strings of JSON data are associated with a table in the database, and the data of the table are also these JSON data strings. Tokens of array type and object type in JSON data are usually used to correspond to columns. Since columns are key information in query requests, for example, query requests usually specify columns and query conditions for column values. Therefore, in this application scenario, if it is found that the column corresponding to the currently parsed token is not needed in this query, then the parsing of the value corresponding to the token can be skipped. If the corresponding column is needed in this query, then it is determined whether the currently parsed column value is within the range required by the query condition. If the column value is not within the range, it means that the current JSON string does not meet the requirements. At this time, the parsing of the current JSON string can be terminated early, thereby greatly reducing the time spent on parsing JSON data and achieving the purpose of performance improvement.

[0037] Specifically, for example, when parsing JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request based on the information specified in the query request may include: when parsing JSON data token by token, judging whether the currently parsed token corresponds to the column specified in the query request; if not, determining that the currently parsed token does not contain the data required by the query request; if corresponding, parsing to obtain the value of the token, and judging whether the value of the currently parsed token needs to be obtained by the query request based on the query conditions specified in the query request; if not, determining that the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0038] Taking the current parsed token as an array type token as an example, the subscript of the array corresponding to the token can be obtained as the column number; and it is determined whether the column number is the column number specified by the query request. For example, when the JSON data contains an array type token such as "[1,2,3,4]", when "[" is parsed, the subscript of the corresponding array can be obtained as the column number. Since the subscript corresponding to the array type token in the JSON data is the number of the corresponding column in the table, the column number can be used to determine whether the column is specified by the query. If the column is not specified by the query, the parsing of the value can be skipped. If it is specified by the query, it can continue to determine whether the value of the token is within the range of the query condition specified by the query request. If not, the parsing of the string of JSON data can be terminated.

[0039] Taking the token currently parsed as an object type token as an example, the object name of the token can be obtained; the object name of the token is used as the column name to determine whether the column name has a corresponding column in the data table; if so, the corresponding column number is obtained; and it is determined whether the column number is the column number specified by the query request. For example, when the JSON data contains an object type token such as "{"column1":1,"column2":2,"column3":3,"column4":4}", when "{" is parsed, "column1" can be obtained as the column name. Since the object name of the object type token in the JSON data is the name of the corresponding column in the table, the column number can be queried using the object name, and then the column number can be used to determine whether the column is specified by the query. If the column is not specified by the query, the parsing of the value can be skipped. If it is specified by the query, it can continue to determine whether the value of the token is within the range of the query condition specified by the query request. If not, the parsing of the string of JSON data can be terminated.

[0040] It should be noted that the token types contained in JSON data are various, generally including: array, object, string, number, Boolean, null value and other types. The data required for the query request is usually the token type corresponding to the specified information, and other types of tokens do not belong to the token type corresponding to the information specified by the query request. When parsing, the parsing of their values ​​can be skipped directly, thereby improving the parsing performance. Therefore, in one or more embodiments of the present specification, when parsing JSON data token by token, it is determined whether the currently parsed token belongs to the token type corresponding to the information based on the information specified in the query request; if not, it is determined that the currently parsed token does not contain the data required by the query request.

[0041] JSON data can also support nesting, such as arrays may be nested in object values, and objects may be nested in array values. In the application scenario where the database introduces JSON data, the bottom layer of the token of the corresponding column is either an array or an object, otherwise it must be data not required by the query request. Therefore, in one or more embodiments of the present specification, when parsing JSON data token by token, it can be determined whether the currently parsed token is an array type or an object type token according to the column specified in the query request. If not, the parsing of the value of the currently parsed token is skipped.

[0042] For example, the content of the input JSON data is: '{"col1":[1,2,{"key":"value"}],"col2":{"key":"value"}}'. If the column specified in the query request is "col2", then during the parsing process, the parsing of the values ​​of the token streams `[`, `1`, `2`, `{`, `"key"`, `"value"`, `}`, `]` will be skipped, and "col2" and its corresponding value will be parsed. It can be seen that the JSON data parser implemented according to the method provided in the embodiment of this specification can greatly reduce the time consumption of analyzing json data and improve the parsing performance.

[0043] In one or more embodiments of the present specification, in order to improve the scalability of the JSON data parser, the JSON data parser implemented according to the method provided in the embodiments of the present specification can communicate with an external module through a set of predefined interfaces. The step of determining whether the currently parsed token corresponds to the column specified by the query request, and the step of determining whether the value of the currently parsed token needs to be obtained by the query request according to the query condition specified in the query request, are executed by requesting an external module through a predefined interface. Thus, the JSON data parser can focus on parsing the token, and the judgment of skipping the parsing of certain tokens or terminating the parsing in advance can be executed by the external module, thereby reducing the coupling between the JSON data parser and the system, making it suitable for accelerated query of any type of database system, and improving the scalability of the JSON data parser.

[0044] In order to make the above embodiments easier to understand, Figure 2 The JSON data parser state flow diagram shown in the figure is used to describe in detail the embodiment of the method provided in the embodiment of this specification for parsing JSON data based on the state flow mechanism and the external module. Figure 2 As shown, in the state flow mechanism of the JSON data parser, when the JSON data includes an array type token, the state flow mechanism includes at least: initial state, array start state, array value state; when the JSON data includes an object type token, the state flow mechanism includes at least: object start state, object name state, skip value state, need value state, object value state.

[0045] InitState (initial state), the JSON data parser parses the input JSON data token by token in a streaming manner in the IniState state. According to the method provided in the embodiment of this specification, in the IniState state, if the currently parsed token is not an array type or object type token, the parsing of the value of the currently parsed token is skipped, and the parsing of the next token is continued. Therefore, before encountering an array type or object type token, the JSON data parser will skip the parsing of the value of the encountered token stream. The JSON data parser enters the ArrStarted state in response to encountering the start token of array type data such as "StarArrToken"; it enters the ObjStarted state when encountering the start token of object type data such as "StartObjToken".

[0046] First of all, Figure 2 The state flow mechanism shown in the figure is described in detail when encountering the start token of array type data:

[0047] ArrStarted (array start status):

[0048] In response to encountering the array value token "ValueToken" in the ArrStarted state, the JSON data parser enters the ValueGot state accordingly.

[0049] In response to encountering the end token "EndArrToken" of array type data in the ArrStarted state, the JSON data parser enters the InitState state accordingly.

[0050] ValueGot (array value status):

[0051] In response to entering the ValueGot state, the JSON data parser obtains the subscript of the array corresponding to the value in the "ValueToken" as the column number, and requests the external module through a predefined interface to execute the step of determining whether the column number is the column number specified by the query request.

[0052] In response to receiving the first negative result returned by the external module in the ValueGot state, the JSON data parser executes "ContParse", that is, parses the next token of the currently parsed token, and enters the ArrStarted state. The first negative result indicates that the column number is not the column specified by the query request.

[0053] In response to receiving the first positive result returned by the external module in the ValueGot state, the JSON data parser requests the external module through a predefined interface to execute the step of determining whether the value of the currently parsed token needs to be obtained by the query request. The first positive result indicates that the column number is the column specified by the query request.

[0054] In response to receiving the second positive result returned by the external module in the ValueGot state, the JSON data parser obtains the value stored in the "ValueToken" and determines whether all the values ​​required by the query request have been obtained. If so, "StopParse" is executed to end the parsing of the JSON data, and the JSON data parser enters the InitState state. If not, "ContParse" is executed to parse the next token of the currently parsed token and enter the ArrStarted state. The second positive result indicates that the value of the token needs to be obtained by the query request.

[0055] In response to receiving the second negative result returned by the external module in the ValueGot state, the JSON data parser executes "StopParse" to end the parsing of the JSON data, and the JSON data parser enters the InitState state. The second negative result indicates that the value of token does not need to be obtained by the query request.

[0056] Below, in Figure 2 The state flow mechanism shown in the figure is described in detail when encountering the start token of object type data:

[0057] ObjStarted, (object start state):

[0058] The JSON data parser enters the KeyGot state in response to encountering the key token "KeyToken" of object type data in the ObjStarted state.

[0059] In response to encountering the end token "EndObjToken" of the object type data in the ObjStarted state, the JSON data parser enters the InitState state.

[0060] KeyGot (get object name status):

[0061] In response to entering the KeyGot state, the JSON data parser obtains the key of the key token of the currently parsed object type data, which is the object name. The JSON data parser requests the external module through a predefined interface to execute the steps of using the object name of the token as the column name, determining whether the column name has a corresponding column in the data table, and, if so, obtaining the number of the corresponding column, and determining whether the column number is the number of the column specified by the query request.

[0062] The JSON data parser enters the IgnoreValue state in response to receiving the third negative result returned by the external module in the KeyGot state. The third negative result indicates that the column name is not a column in the data table or the column number is not a column specified by the query request, that is, the key is "UnusedKey".

[0063] The JSON data parser enters the NeedValue state in response to receiving a third affirmative result returned by the external module in the KeyGot state, the third affirmative result indicating that the column number is the column specified by the query request, that is, the key is "UsedKey".

[0064] IgnoreValue (skip value status):

[0065] The JSON data parser responds by entering the IgnoreValue state, indicating that the value is not needed and the corresponding token does not need to be parsed. Therefore, the parsing of the object value token "ValueToken" is skipped, and the next token is parsed to enter the ObjStarted state.

[0066] NeedValue (need value status):

[0067] In response to entering the NeedValue state, the JSON data parser parses the object value token "ValueToken", obtains the object value, and enters the KeyValueGot state.

[0068] KeyValueGot (object has been valued):

[0069] In response to entering the KeyValueGot state, the JSON data parser requests an external module through a predefined interface to execute the step of determining whether the value of the currently parsed token needs to be obtained by the query request.

[0070] In response to receiving the fourth affirmative result returned by the external module in the KeyValueGot state, the JSON data parser determines whether all values ​​required by the query request have been obtained in response to the fourth affirmative result received from the external module in the KeyValueGot state. If yes, "StopParse" is executed to end the parsing of the JSON data and the JSON data parser enters the InitState state. If not, "ContParse" is executed to parse the next token of the currently parsed token and enter the ObjStarted state.

[0071] It should be noted that Figure 2 The tokens such as StartArrToken and EndArrToken shown in the figure can be tokens with semantics specified by the JSON specification in the JSON data. The tokens mentioned in the method provided in the embodiment of this specification can also be other tokens not mentioned, which will not be repeated here.

[0072] It can be seen from the above embodiments that the method provided in the embodiments of this specification is based on the state transfer mechanism and the external module to parse JSON data, and the parsing performance is efficient and scalable, and can be used to accelerate the query of JSON data in any database system. Through the token-by-token method, the input JSON data is parsed in a streaming manner based on the above state transfer mechanism. From the perspective of column-level filtering, it can be seen that if the column corresponding to the current token is not needed in this query, the parsing of the value corresponding to the token is skipped. If it is found that the columns required for this query have been collected during the parsing process, the parsing of the current row JSON string is terminated early, and the parsing performance is greatly improved. From the perspective of row-level filtering, it can be seen that the performance improvement is analyzed that the query conditions of the columns specified by the query request are used to determine whether the currently parsed column value is within the range required by the query conditions. If it is not within the range, it means that the current JSON string does not meet the requirements. At this time, the parsing of the current row JSON string will also be terminated early, and the parsing performance is further improved. Therefore, based on the method provided in the embodiments of this specification, the parsing of JSON data can be greatly accelerated.

[0073] Corresponding to the above method embodiment, this specification also provides an apparatus embodiment for parsing JSON data. Figure 3 FIG. 1 is a schematic diagram showing a structure of a device for parsing JSON data provided by an embodiment of the present specification. Figure 3 As shown, the device includes: a parsing judgment module 302, a value parsing skipping module 304 and a parsing ending module 306.

[0074] The parsing judgment module 302 may be configured to, when parsing the JSON data token by token, judge whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request according to the information specified by the query request.

[0075] The value parsing skipping module 304 may be configured to skip parsing the value of the currently parsed token if the currently parsed token does not contain the data required by the query request.

[0076] The parsing end module 306 may be configured to end the parsing of the JSON data if the remaining unparsed portion of the JSON data does not contain the data required by the query request.

[0077] The device provided in the embodiment of the present specification parses token by token, skips the parsing of irrelevant data according to the information of the query request, avoids constructing a complete Document Object Tree in the memory, and terminates the parsing of JSON data early when feasible, thereby greatly reducing the time consumption of parsing JSON data and achieving the purpose of efficiently parsing JSON data.

[0078] Figure 4 A schematic diagram of the structure of a device for parsing JSON data provided by another embodiment of the present specification is shown.

[0079] For example, in an application scenario where a database introduces JSON data, the JSON data corresponds to the data in a table in the database. Figure 4 As shown, the analysis and judgment module 302 may include: a column correspondence judgment submodule 3022 , a column negation submodule 3024 , a column confirmation submodule 3026 and a condition exclusion submodule 3028 .

[0080] The column correspondence determination submodule 3022 may be configured to determine whether the currently parsed token corresponds to the column specified by the query request when parsing the JSON data token by token.

[0081] The column negation submodule 3024 may be configured to determine that the currently parsed token does not contain the data required by the query request if the column correspondence determination submodule 3022 determines that there is no correspondence.

[0082] The column confirmation submodule 3026 may be configured to parse the token value if the column correspondence determination submodule 3022 determines the correspondence, and determine whether the currently parsed token value needs to be obtained by the query request according to the query condition specified in the query request.

[0083] The condition exclusion submodule 3028 may be configured to determine that the remaining unparsed portion of the JSON data does not contain the data required by the query request if the column confirmation submodule 3026 determines that it is not required.

[0084] In this application scenario, if it is found that the column corresponding to the currently parsed token is not needed in this query, then the parsing of the value corresponding to the token can be skipped. If the corresponding column is needed in this query, then determine whether the currently parsed column value is within the range required by the query condition. If the column value is not within the range, it means that the current JSON string does not meet the requirements. At this time, the parsing of the current JSON string can be terminated early, thereby greatly reducing the time spent on parsing JSON data and achieving the purpose of improving performance.

[0085] For another example, since when all the values ​​required by the query request have been obtained, there is no need to continue parsing the JSON data, therefore, in one or more embodiments of this specification, Figure 4 As shown, the analysis and judgment module 302 may include: a value-taking submodule 3030 , a value-taking judgment submodule 3032 , and a value-taking end submodule 3034 .

[0086] The value obtaining submodule 3030 may be configured to obtain the value of the token when parsing the JSON data token by token, if the value of the currently parsed token needs to be obtained by the query request.

[0087] The value determination submodule 3032 may be configured to determine whether all values ​​required by the query request have been obtained.

[0088] The value completion submodule 3034 may be configured to determine that the remaining unparsed portion of the JSON data does not contain the data required by the query request if the value determination submodule 3032 determines that it is yes.

[0089] It should be noted that the token types contained in JSON data are various, and the data required by the query request is usually the token type corresponding to the specified information. Other types of tokens do not belong to the token type corresponding to the information specified by the query request. When parsing, the parsing of their values ​​can be directly skipped, thereby improving the parsing performance. Figure 4 As shown, the analysis and judgment module 302 may include: a tag type judgment submodule 3036 and a tag type negation submodule 3038.

[0090] The token type determination submodule 3036 may be configured to determine, when parsing JSON data token by token, whether the currently parsed token belongs to the token type corresponding to the information according to the information specified in the query request.

[0091] The tag type negation submodule 3038 may be configured to determine that the currently parsed token does not contain the data required by the query request if the tag type determination submodule 3036 determines that it is not.

[0092] For example, the token type determination submodule 3036 may be configured to determine whether the currently parsed token is an array type or object type token according to the columns specified in the query request when parsing the JSON data token by token.

[0093] Take the current parsed token as an example, which is an array type token. Figure 4 As shown, the column correspondence judgment submodule 3022 may include: an array number acquisition submodule 3022a and a column number judgment submodule 3022b.

[0094] The array number obtaining submodule 3022a may be configured to obtain the subscript of the array corresponding to the token as the column number if the currently parsed token is an array type token.

[0095] The column number determination submodule 3022b may be configured to determine whether the column number is the column number specified by the query request.

[0096] Take the currently parsed token as an example, which is an object type token. Figure 4 As shown, the column correspondence judgment submodule 3022 may include: an object name acquisition submodule 3022c, a column name judgment submodule 3022d, an object number acquisition submodule 3022e and a column number judgment submodule 3022b.

[0097] The object name acquisition submodule 3022c may be configured to acquire the object name of the token if the currently parsed token is an object type token.

[0098] The column name determination submodule 3022d may be configured to use the object name of the token as the column name, and determine whether the column name has a corresponding column in the data table.

[0099] The object number acquisition submodule 3022e may be configured to acquire the number of the corresponding column if the column name determination submodule 3022d determines that the column name exists.

[0100] The column number determination submodule 3022b may be configured to determine whether the column number obtained by the object number acquisition submodule 3022e is the column number specified by the query request.

[0101] The above is a schematic scheme of a device for parsing JSON data in this embodiment. It should be noted that the technical scheme of the device for parsing JSON data and the technical scheme of the method for parsing JSON data above belong to the same concept, and the details not described in detail in the technical scheme of the device for parsing JSON data can be referred to the description of the technical scheme of the method for parsing JSON data above.

[0102] Figure 5 The structure block diagram of a computing device 500 provided according to an embodiment of the present specification is shown. The components of the computing device 500 include but are not limited to a memory 510 and a processor 520. The processor 520 is connected to the memory 510 via a bus 530, and the database 550 is used to store data.

[0103] The computing device 500 also includes an access device 540 that enables the computing device 500 to communicate via one or more networks 560. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 540 may include one or more of any type of network interface (e.g., a network interface card (NIC)) whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a World Wide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.

[0104] In one embodiment of the present specification, the above components of the computing device 500 and Figure 5 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 5 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.

[0105] The computing device 500 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 500 may also be a mobile or stationary server.

[0106] The processor 520 is used to execute the following computer executable instructions:

[0107] When parsing the JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request according to the information specified by the query request;

[0108] If the currently parsed token does not contain the data required by the query request, the parsing of the value of the currently parsed token is skipped;

[0109] If the remaining unparsed portion of the JSON data does not contain the data required by the query request, the parsing of the JSON data is terminated.

[0110] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the method for parsing JSON data described above belong to the same concept, and the details not described in detail in the technical scheme of the computing device can be referred to the description of the technical scheme of the method for parsing JSON data described above.

[0111] An embodiment of the present specification further provides a computer-readable storage medium storing computer instructions, which are used when executed by a processor to:

[0112] When parsing the JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request according to the information specified by the query request;

[0113] If the currently parsed token does not contain the data required by the query request, the parsing of the value of the currently parsed token is skipped;

[0114] If the remaining unparsed portion of the JSON data does not contain the data required by the query request, the parsing of the JSON data is terminated.

[0115] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the method for parsing JSON data described above belong to the same concept, and the details not described in detail in the technical scheme of the storage medium can be referred to the description of the technical scheme of the method for parsing JSON data described above.

[0116] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0117] The computer instructions include computer program codes, which may be in source code form, object code form, executable files or some intermediate forms, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0118] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the embodiments of this specification are not limited by the order of the actions described, because according to the embodiments of this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the embodiments of this specification.

[0119] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0120] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to only the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of the embodiments of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the embodiments of this specification, so that technicians in the relevant technical field can well understand and use this specification. This specification is only limited by the claims and their full scope and equivalents.

Claims

1. A method for parsing JSON data, comprising: When parsing JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain data required by the query request according to information specified by the query request, wherein the query request is a query request for JSON data in a database, and the query request specifies a column and a query condition for a value of the column; If the currently parsed token does not contain the data required by the query request, the parsing of the value of the currently parsed token is skipped; If the remaining unparsed portion of the JSON data does not contain the data required by the query request, the parsing of the JSON data is terminated.

2. According to the method of claim 1, the JSON data corresponds to the data of a table in a database; When parsing the JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain data required by the query request according to the information specified by the query request includes: When parsing JSON data token by token, determine whether the currently parsed token corresponds to the column specified in the query request; If not, it is determined that the currently parsed token does not contain the data required by the query request; If it corresponds, parse the token value, and determine whether the currently parsed token value needs to be obtained by the query request according to the query condition specified in the query request; If not needed, it is determined that the remaining unparsed portion of the JSON data does not contain the data required by the query request.

3. According to the method of claim 1, when parsing the JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain the data required by the query request according to the information specified by the query request comprises: When parsing JSON data token by token, if the value of the currently parsed token needs to be obtained by the query request, obtain the value of the token; Determine whether all values ​​required by the query request have been obtained; If yes, it is determined that the remaining unparsed portion of the JSON data does not contain the data required by the query request.

4. According to the method of claim 1 or 2, when parsing JSON data token by token, judging whether the currently parsed token does not contain the data required by the query request according to the information specified by the query request comprises: When parsing JSON data token by token, determine whether the currently parsed token belongs to the token type corresponding to the information specified in the query request; If not, it is determined that the currently parsed token does not contain the data required by the query request.

5. According to the method of claim 4, when parsing the JSON data token by token, judging whether the currently parsed token belongs to the token type corresponding to the information specified in the query request comprises: When parsing JSON data token by token, the column is specified according to the query request to determine whether the currently parsed token is an array type or object type token.

6. According to the method of claim 2, the step of determining whether the currently parsed token corresponds to a column specified by the query request comprises: If the currently parsed token is an array type token, get the subscript of the array corresponding to the token as the column number; It is determined whether the column number is the column number specified by the query request.

7. According to the method of claim 2, the step of determining whether the currently parsed token corresponds to a column specified by the query request comprises: If the currently parsed token is an object type token, get the object name of the token; Use the object name of the token as the column name, and determine whether the column name has a corresponding column in the data table; If yes, get the corresponding column number; It is determined whether the column number is the column number specified by the query request.

8. According to the method described in claim 2, the step of determining whether the currently parsed token corresponds to the column specified in the query request, and the step of determining whether the value of the currently parsed token needs to be obtained by the query request based on the query conditions specified in the query request, are executed by requesting an external module through a predefined interface.

9. A device for parsing JSON data, comprising: a parsing judgment module configured to judge, when parsing JSON data token by token, whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain data required by the query request according to information specified by a query request, wherein the query request is a query request for JSON data in a database, and the query request specifies a column and a query condition for a value of the column; A value parsing skip module is configured to skip parsing the value of the currently parsed token if the currently parsed token does not contain the data required by the query request; The parsing end module is configured to end the parsing of the JSON data if the remaining unparsed portion of the JSON data does not contain the data required by the query request.

10. A computing device comprising: Memory and processor; The memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions: When parsing JSON data token by token, judging whether the currently parsed token and / or the remaining unparsed portion of the JSON data does not contain data required by the query request according to information specified by the query request, wherein the query request is a query request for JSON data in a database, and the query request specifies a column and a query condition for a value of the column; If the currently parsed token does not contain the data required by the query request, the parsing of the value of the currently parsed token is skipped; If the remaining unparsed portion of the JSON data does not contain the data required by the query request, the parsing of the JSON data is terminated.

11. A computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the steps of the method for parsing JSON data as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Json format data analytic method and data receiving end

    CN105354020A

  • JSON format data parsing and storing method and device

    CN109144514A

  • Json data analysis method and device and computer readable storage medium

    CN109558128A

  • JSON data analysis method and device, apparatus and storage medium

    CN110554877A

  • Data processing method and device

    CN110968763A