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 !