0
val hostSQLList = jsonObj.getOrElse("hostSQLList", " ").asInstanceOf[List[String]]

var sqlRepMap = mutable.LinkedHashMap[String, Any]()
var sqlStatusMap = mutable.LinkedHashMap[String, Any]()
var sqlSlowQuery = mutable.LinkedHashMap[String, Any]()

hostSQLList.foreach(hostSQL => {
  if (hostSQL != null) {
    sqlRepMap ++= mutable.LinkedHashMap(hostSQL -> AlertDashboard.checkSQLReplicationLag(hostSQL))

    sqlStatusMap ++= mutable.LinkedHashMap(hostSQL -> AlertDashboard.checkSQLStatus(hostSQL))

    sqlSlowQuery ++= mutable.LinkedHashMap(hostSQL -> AlertDashboard.checkSQLSlowQuery(hostSQL))
  }

  else {
    sqlRepMap ++= mutable.LinkedHashMap(hostSQL -> "Found nothing")
    sqlStatusMap ++= mutable.LinkedHashMap(hostSQL -> "Found nothing")
    sqlSlowQuery ++= mutable.LinkedHashMap(hostSQL -> "Found nothing")
  }
})

This is giving me the following output :

{  
   "sqlRepMap":[  
      {  
         "_1":"xyz.com",
         "_2":{  
            "18/09/2014 15:00:39_0":0.0,
            "18/09/2014 15:30:22_0":0.0,
            "18/09/2014 15:49:26_0":0.0
         }
      }
   ],
   "sqlStatusMap":[  
      {  
         "_1":"xyz.com",
         "_2":{  
            "18/09/2014 15:00:39_0":1,
            "18/09/2014 15:30:22_0":1,
            "18/09/2014 15:49:26_0":1
         }
      }
   ],
   "sqlSlowQuery":[  
      {  
         "_1":"xyz.com",
         "_2":{  
            "18/09/2014 15:00:39_0":0,
            "18/09/2014 15:30:22_0":0,
            "18/09/2014 15:49:26_0":0
         }
      }
   ]
}

When I actually want something like this :

{  
   "sqlRepMap":[  
      {  
         "xyz.com":{  
            "18/09/2014 15:00:39_0":0.0,
            "18/09/2014 15:30:22_0":0.0,
            "18/09/2014 15:49:26_0":0.0
         }
      }
   ],
   "sqlStatusMap":[  
      {  
         "xyz.com":{  
            "18/09/2014 15:00:39_0":1,
            "18/09/2014 15:30:22_0":1,
            "18/09/2014 15:49:26_0":1
         }
      }
   ],
   "sqlSlowQuery":[  
      {  
         "xyz.com":{  
            "18/09/2014 15:00:39_0":0,
            "18/09/2014 15:30:22_0":0,
            "18/09/2014 15:49:26_0":0
         }
      }
   ]
}

The same code for insertion in a normal Map is giving me what I want but for a LinkedHashMap it somehow isnt working. Or could there be something wrong with my JSON ParseR? Thanks in advance!

Tanvi
  • 413
  • 1
  • 5
  • 14
  • 4
    I can't see anything in your code that shows how you're converting the maps into JSON. (And since your problem is that the JSON is incorrectly generated, that's the important bit!) – Andrzej Doyle Sep 18 '14 at 11:18
  • I actually dont know the problem. if this looks okay then the problem is with my JSON which i will – Tanvi Sep 18 '14 at 12:49
  • 1
    I can't tell if it looks OK, without knowing what requirements are of the thing you're going to pass it into... – Andrzej Doyle Sep 18 '14 at 14:20

0 Answers0