0

Is it possible to convert a DataFrame containing JSON strings to a DataFrame containing a typed representation of the JSON strings using Spark 2.4?

For example: given the definition below, I'd like to convert the single column in jsonDF using a schema that is inferred from the JSON string.

val jsonDF = spark.sparkContext.parallelize(Seq("""{"a": 1, "b": 2}""")).toDF
1
  • If people who downvote would explain why they are down-voting, that would be helpful and encourage a better community. Commented May 6, 2019 at 14:08

1 Answer 1

1

DataFrameReader can read JSON from string data sets. For example using toDS instead of toDF

val jsonDS = Seq("""{"a": 1, "b": 2}""").toDS
spark.read.json(jsonDS).show()

Output:

+---+---+
|  a|  b|
+---+---+
|  1|  2|
+---+---+
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.