title: I could not find what is mistake in following code?
body: <p>Scenario:
  I  have following case class:</p>
  
  <pre><code>case class Student(firstName:String, lastName: String)
  </code></pre>
  
  <p>I need to write reads and writes for Student. The json I provide is Sequence of Student.
  For Example: </p>
  
  <pre><code>{
    "College": "Abc",
    "student" : [{"firstName" : "Jack", "lastName":"Starc"}, 
                 {"firstName" : "Nicolas", "lastName":"Pooran"}
               ]
  }
  </code></pre>
  
  <p>I have written my reads and writes as:</p>
  
  <pre><code>implicit val studentFormat = Json.format[Student]
  implicit val studentRead = Json.reads[Student]
  implicit val  studentWrite = Json.writes[Student]
  implicit val studentReadSeq = Reads.seq(studentRead)
  implicit val studentWriteSeq = Writes.seq(studentWrite)
  </code></pre>
  
  <p>Now I have to make a type parser and check whether the student is array or simple object. Here key i.e. Student can be Students or StudentInfo. So I have to make a parser on the basis of value provided in json.</p>
  
  <p>For this I have done as following:</p>
  
  <pre><code>def studentCheck(jsonValue:  JsObject) = {
    var modifiedJson = Json.obj()
    for ((key, value) &lt;- jsonValue.value) {
      if(value.validate[Student].isSuccess ) {
        val json = 
          studentFormat.writes(value.validate[Student].get).as[JsObject] 
        modifiedJson.+(key, json)
      }
      else if(studentReadSeq.reads(value).isSuccess) {
        //My Code will be here
        modifiedJson
      }
      else {
        println("Error")
        modifiedJson.+(key,value)
      }
    }
  }
  
  val studentJson = Json.obj(
    "college" -&gt; "ABC",
    "student" -&gt; Json.arr(
      Json.obj("firstName" -&gt; "Jack", "lastName" -&gt; "Starc"),
      Json.obj("firstName" -&gt; "Nicolas", "entity" -&gt; "Pooran")
    )
  )
  
  studentCheck(studentJson)
  </code></pre>
  
  <p>The problem I get here is, even provided List of Students the first case i.e. if statement is executed instead of elseif. How can I validate so it satisfy all the condition, i.e if Student object is provided if statement is executed and if List of Student is provided elseif statement is executed.</p>