I have an input file ("student.json") that consists of a few lines of JSON code such as:
{"name":"Josh","age":22,"gender":"M"}
that will be used in a Java program. The program should input the file, grab a JSON string, and then use a character stack to validate the syntax (the program should ignore what the specific property [name] and value [Josh] is, but know that each set of braces MUST have at least 2 values with a colon between). If the syntax is correct the console will tell the user that the JSON string is valid, if it is not valid the console will say so.
For the character stack I am to loop through each character of the JSON string. When an opening brace or bracket is encountered the program should push it on the stack. When a closing brace or bracket is encountered the program should then pop a value off the stack and see if it matches. I am also supposed to use the isEmpty method to see if there are unmatched symbols.
I have never used a character stack before. I know how to do the rest of the Java program, it is just the stack I am stuck on.
Question: How do I validate the JSON string using this character stack and the requirements?
Deque<Character>for your stack. But please don't expect that we will provide you with a complete solution here. It is your homework, after all.{character indicating the start of a new JSON object.