0

I'm currently working on a lightning component with a lightning tree grid. So, I'm serializing my output as JSON and it's working fine but fetching type attributes array too. How to remove a variety from the JSON output.

Please guide me how to handle this.

My code:

 List<Map<Object, Object>> l = new List<Map<Object, Object>>();
        if(plist<> null && plist.isEmpty() == false)
        {                
            for(AggregateResult agg:AllSDRs.keyset())
            {
                Map<Object, Object> m = new Map<Object, Object>();
                m.put('Original_SDR__c',agg.get('Original_SDR__c'));
                m.put('TotalAmount',agg.get('TotalAmount'));
                m.put('TotalCommission',agg.get('TotalCommission'));
                if(AllSDRs.get(agg).containskey((String)agg.get('Original_SDR__c')))
                {
                    m.put('_children',AllSDRs.get(agg).get((String)agg.get('Original_SDR__c')));
                }
                l.add(m);
            }
            String jsonString = JSON.serialize(l);
            //String jsonString = String.valueof(l);
            System.debug('@@@JSON_serliaze@@@'+jsonString); 
        }

My out put:

[
  {
    "_children": [
      {
        "attributes": {
          "type": "Opportunity",
          "url": "/services/data/v58.0/sobjects/Opportunity/0065600000Ngd4KAAR"
        },
        "Id": "0065600000Ngd4KAAR",
        "Name": "Test"
      },
      {
        "attributes": {
          "type": "Opportunity",
          "url": "/services/data/v58.0/sobjects/Opportunity/0065600000NgcY1AAJ"
        },
        "Id": "0065600000NgcY1AAJ",
        "Name": "ABC"
      }
    ],
    "TotalCommission": 600,
    "TotalAmount": null,
    "Original_SDR__c": "Jake Koch"
  },
  {
    "_children": [
      {
        "attributes": {
          "type": "Opportunity",
          "url": "/services/data/v58.0/sobjects/Opportunity/0065600000Nggu1AAB"
        },
        "Id": "0065600000Nggu1AAB",
        "Name": "ABC Plumbing."
      }
    ],
    "TotalCommission": 300,
    "TotalAmount": null,
    "Original_SDR__c": "Pavan Kumar"
  }
]
5
  • 1
    Check this thread out - salesforce.stackexchange.com/questions/33690/….
    – NedlaV
    Jul 20, 2023 at 16:14
  • Do you mind posting your full apex class?
    – prem22
    Jul 20, 2023 at 16:15
  • @prem22 still i'm developing the code. i'm missing anything over here
    – Pavan tej
    Jul 20, 2023 at 16:32
  • 1
    @NedlaV it worked thanks buddy.
    – Pavan tej
    Jul 20, 2023 at 17:08
  • I am sorry initially, I was thinking it might be query returning the additional properties, but since you found an answer, it's okay.
    – prem22
    Jul 20, 2023 at 17:25

0

You must log in to answer this question.

Browse other questions tagged .