Scala: Read JSON file as Spark DataFrame

Raymond Raymond visibility 619 event 2020-12-16 access_time 3 years ago language English

In article Scala: Parse JSON String as Spark DataFrame, it shows how to convert an in-memory JSON string object to a Spark DataFrame. This article shows how to read directly from a JSON file. In fact, this is even simpler. 

Read from local JSON file

The following code snippet reads from a local JSON file named test.json.

The content of the JSON file is:


Code snippet

|  ABC|  1|
|  DEF|  2|
|  GHI|  3|

Read from HDFS JSON file

The following code snippet reads from a path in HDFS (/big-data/test.json):

More from Kontext
info Last modified by Raymond 3 years ago copyright This page is subject to Site terms.
Like this article?
Share on
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts