Skip to content

Coding Challenge #2 - Build a JSON Parser | John Crickett

License

Notifications You must be signed in to change notification settings

MohamedBsh/scala-json-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scala JSON Parser

Description

This project implements a JSON parser in Scala that validates JSON strings and determines if they are valid or invalid based on their format.

Environment Setup

Prerequisites

  • Java (version 8 or higher)
  • Scala (version 2.13 or higher)
  • SBT (Scala Build Tool)

Installation Steps

  1. Install Java: Verify Java installation with:
    java -version
  2. Install Coursier: Use Homebrew to install Coursier for Scala dependency management:
    brew install coursier/formulas/coursier && cs setup
  3. Install SBT: Install SBT via Homebrew:
    brew install sbt
  4. Create build.sbt: At the project root, create a build.sbt file with:
    name := "JsonParser"
    
    version := "0.1"
    
    scalaVersion := "2.13.8"
  5. Download Test Data: For testing, download JSON test data from Coding Challenge 2 and place it in the data/ directory.

Running the Project

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)

Example JSON Files

  • 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
    }

Expected Output

  • 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.
    

About

Coding Challenge #2 - Build a JSON Parser | John Crickett

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages