cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3975
Views
10
Helpful
2
Replies

Get the length of a JSON Array in CCX

brunonogaki
Level 1
Level 1

Hello,

 

Does anybody know how to get the length of a JSON Array in CCX Scripting?

 

I have the following JSON:

{
    "value": [
        {
            "item1": 1,
            "item2": 2
        },
        {
            "item1": 3,
            "item2": 4
        },
    ]
}

 

So, this is an array of 2 items.

 

I tried to use the step Get JSON Document Data, using values such as "$.value[length]". This filter works in http://jsonpath.com/, but CCX does not recognize it.

 

Is there an easy way to get this information? Maybe with a Java step (preferably not importing any Class to CCX).

 

Thank you,

 

Bruno

 

 

 

1 Accepted Solution

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee
Oh I see. Yeah so, UCCX uses the jayway implementation of JSONPath:
https://github.com/json-path/JsonPath

And therefore, you're testing should be done in a jayway compliant tester:
https://jsonpath.herokuapp.com/

You'll notice that in jayway you would use the following syntax to obtain the length of an array:
"$.value.length()"

And you'll need to assign it to an int type variable. See if that gets you where you want to be.

View solution in original post

2 Replies 2

Anthony Holloway
Cisco Employee
Cisco Employee
Oh I see. Yeah so, UCCX uses the jayway implementation of JSONPath:
https://github.com/json-path/JsonPath

And therefore, you're testing should be done in a jayway compliant tester:
https://jsonpath.herokuapp.com/

You'll notice that in jayway you would use the following syntax to obtain the length of an array:
"$.value.length()"

And you'll need to assign it to an int type variable. See if that gets you where you want to be.

That's it, mate! :)

 

Thank you so much!!!

 

Bruno