Patterson
Patterson

Reputation: 2771

Scala error: object XML is not a member of package org.json on Apache Spark

I am trying to execute the followng scala code but I keep on getting the following error:

command-3313750897057320:1: error: object XML is not a member of package org.json

The full error looks like the following:

enter image description here

The code is as follows:

import org.json.XML
import scala.util.Try

val parseXmlToJson = udf((value: String) => 
                         try{
                             XML.toJSONObject(value).toString
                         }
                         catch{
                           case e: Exception => "Processing Error"
                         }
                        )
  // Defined UDF to parse xml to json

spark.udf.register("XmlToJson", parseXmlToJson)

The objective of the code is to convert/parse XML to JSON.

Upvotes: 0

Views: 805

Answers (1)

Rakhi Agrawal
Rakhi Agrawal

Reputation: 917

Adding java-json.jar to classpath should fix the issue. org.json.XML could be imported if and only if the mentioned jar is added to classpath.

Upvotes: 1

Related Questions