This project is a JSON parser written in Java.
- Java 21 or higher
- Maven
From the project root, run:
mvn clean package
To validate a JSON string from Java code:
import com.jsonparser.JsonParser;
import com.jsonparser.exceptions.JsonParseException;
public class Main {
    static void main(String[] args) {
        String json = "{\"key\": \"value\"}";
        try {
            boolean valid = JsonParser.validate(json);
            System.out.println("Is JSON valid?: " + valid);
        } catch (JsonParseException e) {
            System.out.println("Parse error: " + e.getMessage());
        }
    }
}You can validate JSON from the terminal using the Main class. For example:
- Save your JSON in a file, e.g. data.json.
- Run:
mvn clean package
java -cp target/json-parser-1.0-SNAPSHOT.jar com.jsonparser.Main < data.json
You can also type the JSON directly in the terminal and finish with Ctrl+Z (Windows) or Ctrl+D (Linux/Mac):
java -cp target/json-parser-1.0-SNAPSHOT.jar com.jsonparser.Main
{"key": "value"}
The program will print "Valid JSON" if the JSON is correct, or "Invalid JSON: ..." if there are errors.
To run the tests:
mvn test
- src/main/java/com/jsonparser/: Parser source code
- src/test/java/com/jsonparser/: Unit tests
- Ruben Garcia