cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
122
Views
5
Helpful
2
Replies
Beginner

Get the length of a JSON Array in CCX

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

 

 

 

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
VIP Advisor

Re: Get the length of a JSON Array in CCX

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.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
2 REPLIES 2
Highlighted
VIP Advisor

Re: Get the length of a JSON Array in CCX

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.

Anthony Holloway

Please use the star ratings to help drive great content to the top of searches.
Beginner

Re: Get the length of a JSON Array in CCX

That's it, mate! :)

 

Thank you so much!!!

 

Bruno

 

CreatePlease to create content
Content for Community-Ad
August's Community Spotlight Awards