This project implements a JSON parser in Scala that validates JSON strings and determines if they are valid or invalid based on their format.
- Java (version 8 or higher)
- Scala (version 2.13 or higher)
- SBT (Scala Build Tool)
- Install Java: Verify Java installation with:
java -version
- Install Coursier: Use Homebrew to install Coursier for Scala dependency management:
brew install coursier/formulas/coursier && cs setup
- Install SBT: Install SBT via Homebrew:
brew install sbt
- Create
build.sbt
: At the project root, create abuild.sbt
file with:name := "JsonParser" version := "0.1" scalaVersion := "2.13.8"
- Download Test Data: For testing, download JSON test data from Coding Challenge 2 and place it in the
data/
directory.
To run the project, use the following command in the terminal at the project root:
sbt run
sbt "run stepX" # Replace X with the desired step number (in data/tests folder)
-
Invalid JSON Example (
data/tests/step4/invalid.json
):{ "key": "value", "key-n": 101, "key-o": { "inner key": "inner value" }, "key-l": ['list value'] // Invalid due to single quotes }
-
Valid JSON Example (
data/tests/step4/valid2.json
):{ "key": "value", "key-n": 101, "key-o": { "inner key": "inner value" }, "key-l": ["list value"] // Valid with double quotes }
-
Running the invalid JSON file will result in:
/path/to/invalid.json is an invalid JSON.
-
Running the valid JSON file will result in:
/path/to/valid2.json is a valid JSON.