cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically convert Spark DataFrame to Nested json using Spark Scala

suman9872
New Contributor II

I want to convert the DataFrame to nested json. Sourse Data:-

DataFrame have data value like :- As image 2

Expected Output:-

I have to convert DataFrame value to Nested Json like : -As image 1

Appreciate your help !

1 REPLY 1

Kaniz
Community Manager
Community Manager

Hi @Suman Mishra​, This article explains how to convert a flattened DataFrame to a nested structure by nesting a case class within another case class.

You can use this technique to build a JSON file that can then be sent to an external API.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.