cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

How would i retrieve data JSON data with namespaces using spark SQL?

rammy
Contributor III

File.json from the below code contains huge JSON data with each key containing namespace prefix(This JSON file converted from the XML file).

I could able to retrieve if JSON does not contain namespaces but what could be the approach to retrieve records/values if each key is with a namespace prefix?

jsondf = spark.read.json("<path>/file.json")
 
#jsondf.printSchema()
jsondf.createOrReplaceTempView("ramp")
 
elements = spark.sql("SELECT * FROM ramp")
elements.show()
 

Here,I wanted to retrieve records of w: document/w.body/w:p. I tried different ways but nothing is working. Any suggestions really helpful

image.pngimage

3 REPLIES 3

Pat
Honored Contributor III

HI @Ramesh Bathini​ ,

not sure what you have tried, but maybe you can try this way:

 select `w:document`.`w.body`.`w:p` from ramp

rammy
Contributor III

Thanks alot @Pat Sienkiewicz​  for your response. It works for me

SS2
Valued Contributor

I case of struct you can use (.) For extracting the value

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!