title: How to get sum of nested JSON elements in Long format using scala and play?
body: <p>I have nested JSON like - </p>
  
  <pre><code>"disks" : [ {
          "name" : "v2.16",
          "diskAggregate" : "aggr0",
          "diskRPM" : 15000,
          "totalSizeBytes" : 1077477376,
          "vendorId" : "NETAPP  ",
          "usedBytes" : 1070071808,
          "diskType" : "FCAL",
          "uuid" : "4E455441:50502020:56442D31:3030304D:422D465A:2D353230:32353836:30303030:00000000:00000000",
          "portName" : "FC:A ",
          "raidGroup" : "rg0"
      }, 
      {
          "name" : "v4.16",
          "diskAggregate" : "aggr0",
          "diskRPM" : 15000,
          "totalSizeBytes" : 1077477376,
          "vendorId" : "NETAPP  ",
          "usedBytes" : 1070071808,
          "diskType" : "FCAL",
          "uuid" : "4E455441:50502020:56442D31:3030304D:422D465A:2D353230:32353633:34333030:00000000:00000000",
          "portName" : "FC:B ",
          "raidGroup" : "rg0"
      }]
  </code></pre>
  
  <p>I want to get addition 'totalSizeBytes' from above list of objects.</p>
  
  <p>I used following code to get it -</p>
  
  <pre><code>val storageDevices = "above given json".toList   
  val totalCapacity = storageDevices.foldLeft(0) {
      case (sumOfAllDevices, storageDevice) =&gt;
        val sumOfTotalBytesOnStorageDevice = storageDevice.disks.foldLeft(0) {
          case (totalBytesOnDevice, disk) =&gt;
            totalBytesOnDevice + disk.usedBytes.getOrElse(0).toString.toInt
        }
        sumOfAllDevices + sumOfTotalBytesOnStorageDevice
      // Logger.info("dss"+sumOfTotalBytesOnStorageDevice.toString.toInt)
    }
  </code></pre>
  
  <p>This code gives me total capacity in Integer format. But as there are too many objects in disks array, the totalCapacity will get exceed int. So I wanted to convert it to Long while doing addition.</p>
  
  <p>I want following output-</p>
  
  <pre><code>"totalCapacity": [
    {
      "name": "192.168.20.22",
      "y": 123456789
    }
  ]
  </code></pre>
  
  <p>How do I convert it to Long to get exact sum of all 'totalBytesAvailable' from array/list??? </p>