Skip to content

rubengarcia0510/json-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JSON Parser

This project is a JSON parser written in Java.

Requirements

  • Java 21 or higher
  • Maven

Build

From the project root, run:

mvn clean package

Usage

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());
        }
    }
}

Command Line Usage

You can validate JSON from the terminal using the Main class. For example:

  1. Save your JSON in a file, e.g. data.json.
  2. 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.

Tests

To run the tests:

mvn test

Structure

  • src/main/java/com/jsonparser/ : Parser source code
  • src/test/java/com/jsonparser/ : Unit tests

Author

  • Ruben Garcia

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages