function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lakshmi surendranlakshmi surendran 

Read nested JSON

I need to read ContactID from my below JSON.  I used this code to read the fieldvalue, but returning null. 

StripeJSON = StripeChargeParser.parse(RestContext.request.requestBody.toString());
             if (StripeJSON.type == 'charge.succeeded') {       
                system.debug('ContactId:'+StripeJSON.data
                            );


{
  "id": "evt_3LAK6BBp4qEbkdeL1hyxcg7K",
  "object": "event",
  "data": {
    "object": {
      "id": "ch_3LAK6BBp4qEbkdeL1YeUC11P",
      "object": "charge",
      "amount": 100,
      "amount_captured": 100,
      "amount_refunded": 0,
      "balance_transaction": "txn_3LAK6BBp4qEbkdeL1I0CRyU4",
      "billing_details": {
        "address": {
          "city": null,
          "country": null
        },
        "email": null,
        "name": "LakshmiSuren",
        "phone": null
      },

      "invoice": null,
      "livemode": false,
      "metadata": {
        "ContactID": "0038J000001Q8IpQAK",
        "created_by": "FormAssembly - Stripe - Reference: Form 156 / Conn. 302 / Resp. 92945"
      }
}
}
}
Pavan Gunda 4Pavan Gunda 4
JSONParser parser = JSON.createParser();
while(parser.nextToken()!=null){
 if(parser.getText()=='ContactID'){
  System.debug(parser.nextToken());
}
}
Pavan Gunda 4Pavan Gunda 4
If You think, it is useful. Please respond back