title: find the sum on json list based on condition in pyspark
body: <p>Nested Json sample:</p>
  <pre><code>{
      &quot;accounts&quot;: {
          &quot;1&quot;: [{
              &quot;userId&quot;: &quot;XXXXXXX&quot;,
              &quot;accountId&quot;: &quot;1&quot;,
              &quot;externalId&quot;: &quot;XXXXXXXXXX&quot;,
              &quot;status&quot;: &quot;x&quot;,
              &quot;planId&quot;: &quot;1&quot;,
              &quot;investmentObjective&quot;: null,
              &quot;vestedBalance&quot;: 50097.01,
              &quot;payoutAction&quot;: &quot;0&quot;,
              &quot;payoutAmount&quot;: 0.0,
              &quot;bacs&quot;: &quot;xxx-xxxx-xxxx&quot;,
              &quot;rkId&quot;: &quot;xxx&quot;,
              &quot;planOwnerId&quot;: &quot;xxxx&quot;,
              &quot;userExternalId&quot;: &quot;xxxxxxx&quot;
          }],
          &quot;2&quot;: [{ 
              &quot;userId&quot;: &quot;XXXXXXX&quot;,
              &quot;accountId&quot;: &quot;2&quot;,
              &quot;externalId&quot;: &quot;XXXXXXXXXX&quot;,
              &quot;status&quot;: &quot;X&quot;,
              &quot;planId&quot;: &quot;1&quot;,
              &quot;investmentObjective&quot;: &quot;I&quot;,
              &quot;vestedBalance&quot;: 00.0,
              &quot;payoutAction&quot;: &quot;0&quot;,
              &quot;payoutAmount&quot;: 50097.01,
              &quot;bacs&quot;: &quot;xxx-xxxx-xxxx&quot;,
              &quot;rkId&quot;: &quot;xxx&quot;,
              &quot;planOwnerId&quot;: &quot;xxxxxx&quot;,
              &quot;userExternalId&quot;: &quot;xxxxxxx&quot;
          
          }],
          &quot;3&quot;: [{ 
              &quot;userId&quot;: &quot;XXXXXXX&quot;,
              &quot;accountId&quot;: &quot;3&quot;,
              &quot;externalId&quot;: &quot;XXXXXXXXXX&quot;,
              &quot;status&quot;: &quot;X&quot;,
              &quot;planId&quot;: &quot;1&quot;,
              &quot;investmentObjective&quot;: &quot;I&quot;,
              &quot;vestedBalance&quot;: 00.0,
              &quot;payoutAction&quot;: &quot;0&quot;,
              &quot;payoutAmount&quot;: 2100.00,
              &quot;bacs&quot;: &quot;xxx-xxxx-xxxx&quot;,
              &quot;rkId&quot;: &quot;xxx&quot;,
              &quot;planOwnerId&quot;: &quot;xxxxxx&quot;,
              &quot;userExternalId&quot;: &quot;xxxxxxx&quot;
          
          }]
      }
  }
  </code></pre>
  <p>I need to calculate the “sumpayoutamount” on the below condition</p>
  <p>“sumpayoutamount”: SUM(payoutAmount) of accounts with investmentObjective = &quot;I&quot;</p>
  <p>Above example : “sumpayoutamount”: 50097.01 + 2100.00 for investmentObjective = &quot;I&quot;</p>
  <p>How do i achieve this in Pyspark? Thanks</p>