CA API Gateway: JSON Path Length Function

Document ID : KB000123735
Last Modified Date : 26/12/2018
Show Technical Document Details
Introduction:
When trying to extract the length of the sub field in a JSON document using the length function you are not seeing the desired result.

Example:

JSON:

[{
        "firstName": "John",
        "lastName": "Doe",
        "age": 35
    },
    {
        "firstName": "Jane",
        "lastName": "Doe",
        "age": 30
    }
]

JSON Path Expression:
 [*].firstName.length()

Expected Result:
4
4

Actual Result:
Error/null values
Instructions:
With our support for the Length function it is intended to return the number of elements within a JSON Array, not the individual element character count.

Example:

JSON:
[{
    "firstName": {
        "first": "Jon",
        "Middle": "Snow"
    },
    "lastName": "doe",
    "age": 26
}]

Result:
2