cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2467
Views
0
Helpful
9
Replies

Json Path using Variable

Huth S0lo
Level 1
Level 1

Hi Everyone.  New cisco account, so it looks like I'm new here.  But I've been around for about a decade now.  Over the last couple of years, I've deep dove in to Python programming, and gotten pretty competent in it.  I'm a Cisco voice engineer by trade.  I've done plenty of basic uccx scripts over the years, and finally feel ready to go further.

I'm working on a on call rotation script.  I have to say, the way that uccx parses data is pretty horrendous.  It took me all day to figure out how to count the number of items in an array.  I was trying to get things working with XML until I saw json is an option.  I know json construction well, but have found it very difficult within the uccx editor.

I've gotten to the point that I can pull in a JSON, and count the number of items in the array (which will change over time of course).  I have the script able to do all the math to determine the value it needs.  I have that number set in an integer.  But I cannot figure out how to use the integer as part of the json path.

"$.oncallList[0]"

The above is a proper location, where I could pull data.  I need to use a variable where position 0 is on this path.  I've tried

"$.oncallList[ (rotation_number) ]"
"$.oncallList[ int(rotation_number) ]"
"$.oncallList[rotation_number]"

 

None of those work.  How do I use the rotation_number variable as the item number?

9 Replies 9

Huth S0lo
Level 1
Level 1

Solved my problem.  Had to build my xpath as a string variable, and then use that variable inside the get json data.

Uccx scripting is totally lame.

The get JSON steps needs the value to be a string, so if you’re using a variable it has to be in the form of a string. Once you get over the hump of initial difficulties CCX scripting is actually quite powerful. I give you that it is somewhat quirky and sometimes downright annoying, but it is not all that different from learning any other new developer tool.



Response Signature


screenshot or the detailed explanation will be appreciated. I have json as string and i need to get specific parameter value from it, I am stuck on this task. for 2 days now, started working on this 2 days back.

Maybe this could help you?

image.png



Response Signature


thanks for quick response, can you explain how you converted response of string type to Document type .
I have response string which look like this, i get ot from 'Make rest call'
 
U "{\"count\":1,\"next\":null,\"previous\":null,\"results\":[{\"id\":1,\"url\":\"http://xx.xx.xx.xx:xxxx/api/circuits/providers/1/\",\"display\":\"it\",\"name\":\"it\",\"slug\":\"it\",\"account\":\"\",\"description\":\"\",\"comments\":\"\",\"asns\":[],\"tags\":[],\"custom_fields\":{},\"created\":\"2023-03-\",\"last_updated\":\"2023-03-20T12: \",\"circuit_count\":1}]}"

it contains 'U' at start and seems not valid json(uccx is converting it , checked with other tools like postman other service provide response with valid json), my requirement is to get the 'name' parameter from it which is inside the 'results' array. 

Thanks in advance.

The make JSON call stores the result and any other output from it in variables that are of the type string. Then the result variable is used to create the JSON document.

image.png



Response Signature


Huth S0lo
Level 1
Level 1

I found it to be rather counter intuitive.  I'm used to doing things in Python, which dealing with jsons in python is a snap.  Not so much in the uccx editor.  But then again, I dont write things in java.  I'll attach the script I wrote, and the config file.

HuthS0lo_0-1679499852860.png

 

Huth S0lo
Level 1
Level 1

Sorry, forgot to also attach the python script I wrote to easily update the json file.

@Huth S0lo 

I checked your file and not able to see the Make REST Call. Once you created the Make Rest call  go to properties and update details accordingly. Roger Kallberg  already shared the information.