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
Jaya Prakash MerepalaJaya Prakash Merepala 

how to count objects in json

How can I count the number of objects I received in JSON response?
In the below response I got two objects (id:1234, id:2345) and I want a variable that shows the total number of objects received in response is 2.
I tried using Object.keys(jsonBody).length but this is not working in Salesforce.
I also tried
JSONParser = JSON.createdParser(jsonBody) but this is not giving me the count of objects.

[
    {
        "id" : 1234,
        "organization_id" : 9123,
        "location_id" : 123,
        "name" : "Organizatoin Name",
        "services" : [
            {
                "id" : 1234,
                "service_id" : 987

            },
            {
                "id" : 1234,
                "service_id" : 678
            }
        ]
    },
    {
        "id" : 2345,
        "organization_id" : 8123,
        "location_id" : 123,
        "name" : "Company Name",
        "services" : [
            {
                "id" : 2626,
                "service_id" : 987

            },
            {
                "id" : 2727,
                "service_id" : 678
            }
        ]
    }
]
Any kind of help of appreciated. Thanks.!
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Prakash,

Did you try parsing into List and then finding the size of the List?

Thanks,