To convert a file containing CSV into JSON format, there are a few classes in com.fasterxml.jackson package.

Using maven dependency below


Here is what I tried in Scala

import com.fasterxml.jackson.dataformat.csv.CsvSchema
import com.fasterxml.jackson.dataformat.csv.CsvMapper
import com.fasterxml.jackson.databind.ObjectMapper

def csvFileToJson(filePath: String): String = {
  val inputCsvFile = new File(filePath)

  // if the csv has header, use setUseHeader(true)
  val csvSchema = CsvSchema.builder().setUseHeader(true).build()
  val csvMapper = new CsvMapper()

  // java.util.Map[String, String] identifies they key values type in JSON
  val readAll = csvMapper
    .readerFor(classOf[java.util.Map[String, String]])

  val mapper = new ObjectMapper()

  // json return value

This returns JSON as a string. So, if you want to convert that into a case class in Scala, you can try play-json.