title: Getting due to data type mismatch: argument 2 requires integral type error while parsing Json data Spark SQL
body: <p>i am trying to parse the JSON data, for that i wrote custom schema for this. while parsing the data by adding schema or without adding the schema i am getting following error:</p>
  
  <pre><code>Exception in thread "main" org.apache.spark.sql.AnalysisException: cannot resolve '`queryResults`.`searchResponse`.`response`.`docs`.`transactions`['code']' due to data type mismatch: argument 2 requires integral type, however, ''code'' is of string type.;;
  </code></pre>
  
  <p>Here is my sample data:</p>
  
  <pre><code>{
      "queryResults": {
          "searchResponse": {
              "response": {
                  "docs": [{
                      "transactions": [{
                          "recordDate": "2010-02-02 00:00:00",
                          "code": "PGM/",
                          "description": "Recordation of Patent Grant Mailed"
                      }, {
                          "recordDate": "2010-01-13 00:00:00",
                          "code": "WPIR",
                          "description": "Issue Notification Mailed"
                      }, {
                          "recordDate": "2009-12-17 00:00:00",
                          "code": "R1021",
                          "description": "Receipt into Pubs"
                      }]
                  }]
              }
          }
      }
  }
  </code></pre>
  
  <p>Here is my schema:</p>
  
  <pre><code>val schema=StructType(List(
        StructField("queryResults",StructType(
          List(StructField("searchResponse",StructType(
            List(StructField("response",StructType(
              List(StructField("docs",ArrayType(StructType(
                List(
                  StructField("appCustNumber", StringType, nullable = true),
                  StructField("transactions",ArrayType(StructType(
                    List
                    (
                      StructField("code", StringType, nullable = true),
                      StructField("description", StringType, nullable = true),
                      StructField("recordDate", StringType, nullable = true)
                    )
                  )))
                )
              ))))
            )))
          )))
        ))
      ))
  </code></pre>
  
  <p>Here is how my i am trying to fetch the data:</p>
  
  <pre><code>val dff = sqlCotext.read.schema(schema).json("file locatiuon")
  dff.select("queryResults.searchResponse.response.docs.transactions.code").show()
  </code></pre>
  
  <p>Thanks in Advance.</p>