Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala read Json file as Json

I would like to read a Json file as Json without parsing. I do not want to use a data frame , I would only like to read it as a regular file with the format still intact. Any idea ? I tried reading using wholtextfile but that creates a df.

like image 593
RData Avatar asked Oct 16 '25 07:10

RData


1 Answers

Since you didn't accept the spark specific answer maybe you could try with a normal scala solution like this (using the spray-json library):

import spray.json._

val source = scala.io.Source.fromFile("yourFile.txt")
val lines = try source.mkString finally source.close()
val yourJson = lines.parseJson
like image 83
Florian Baierl Avatar answered Oct 17 '25 20:10

Florian Baierl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!