# JSONParser **Repository Path**: cocoadapter/jsonparser ## Basic Information - **Project Name**: JSONParser - **Description**: A simple JSON parser, for homework of Compiler Principle, ISS, Wuhan University. - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-05-17 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # JSONParser A simple & slow & naive JSON parser for parsing JSON text and extracting information from the text. Compiler Principle 2-rd homework, for Brilliant Class of 2015 grade, ISS, Wuhan University. *by CocoAdapter* ## Grammar ``` ::= | ::= "{" "}" | "{" "}" ::= | "," ::= ":" ::= "[" "]" | "[" "]" ::= | "," ::= | | | | "true" | "false" | "null" ::= | | ``` ## Method recursive-decent ## Requirements All test cases are encoded with UTF-8. ``` Input 1: { "id": 2333, "name": "compiler" } Output 1: valid Input 2: { "id": 2333"name": "compiler" } Output 2: line 2, position 12: expected <,> ``` For abcd below, if there are no errors while parsing JSON text, just output “valid”; otherwise, point out where errors are (line number and start position) and why they happened. > a. Parsing JSON’s basic structure, includes key-value pair, object, array, string;(10pts) > b. Parsing ”true”, “false”, ”null”, integer; (5pts) > c. Parsing floating point number; (5pts) > d. Parsing scientific notation; (5pts) > e. Formatting JSON text to a pretty format. Add a command argument “-pretty” to your program, if there are no errors after parsing file “*.json”, output a formatted pretty JSON text to another file named “*.pretty.json”; (5pts) You can find a disordered JSON text named “country.json” and a pretty JSON text named “country.pretty.json” in directory “test/e/”. For example, your program is named “json”, so commands should be like this: ``` json –pretty *.json ``` > f. For any JSON text and a given query path, you can find the specified value and determine the type of that value (string? floating point numbers? object? array? etc.). (10pts) For example, for the supplied file country.json, let us suppose that the query path is “/RECORDS[35]/countryname”, so it means extracting the value of the “countryname” field of the 35th object of the array corresponding to the “RECORDS” field, that is, a string "China"; if it doesn’t exist, just return null. You are free to design the representation of query path. JSON itself is just like a tree structure, so in this part, what you should focus on is how to express the query path and how to query the required information, you can refer to XML’s parsing (XPath), but there is no need to be exactly the same.