cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3643
Views
12
Helpful
11
Replies

CCX Get JSON Document Data parsing error JSONArray cannot be cast to String

Hi Everyone,

 

Trying to verify passing of data and extraction of value using local test json-server before testing with CRM

 

JSON Path expression - "$..first_name" looks correct, validated online with jsonpath.com and Postman's JSONpath Visualizer. Tried with these other Path expressions - "$.*.first_name" & "$.[0].first_name" that show results in Postman but they do not work in CCX. 

 

json file >
{"employees": {"first_name": "John","last_name": "Doe"}}

 

'Get JSON Document Data' step does not seem to like the data format in received Response Body from the json-server. Testing the Get JSON/Create JSON steps on a locally uploaded file in script works. 

 

Response Body >
TEXT[{\n \"first_name\": \"John\",\n \"last_name\": \"Doe\"\n}]

 

Debugging errors as "...net.minidev.json.JSONArray cannot be cast to java.lang.String...". Attached complete message along with debug step. Appreciate any help to get past this.

 

2 Accepted Solutions

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

As I pointed out in a previous post, UCCX doesn't use the same parser as jsonpath.com.

 

https://community.cisco.com/t5/contact-center/get-the-length-of-a-json-array-in-ccx/m-p/3907604/highlight/true#M112496

 

So, be sure to test your json path expressions in the correct parser, just so you don't end up driving yourself mad wondering why it works in one, but not the other.

 

If you are simply trying to get the first name, then all you need is this:

$.first_name

 

View solution in original post

Try sending this header in your request:

Accept: application/json

;)

View solution in original post

11 Replies 11

Sean Lynch
Level 7
Level 7

 

Check the named value pair in the previous step.  What is the schema difference?  and the subsequent Get JSON Document data is updated for 'first_name" ...?  (dot dot at the beginning?)  I see one is team.teamname | employees.firstname - maybe?  I am learning this too...  so please post back if you figure it out.  

-Sean

2020-0406-namedValuePair.png

Anthony Holloway
Cisco Employee
Cisco Employee

As I pointed out in a previous post, UCCX doesn't use the same parser as jsonpath.com.

 

https://community.cisco.com/t5/contact-center/get-the-length-of-a-json-array-in-ccx/m-p/3907604/highlight/true#M112496

 

So, be sure to test your json path expressions in the correct parser, just so you don't end up driving yourself mad wondering why it works in one, but not the other.

 

If you are simply trying to get the first name, then all you need is this:

$.first_name

 

Hi Anthony,

 

That was the thing, Jayway JSON parser! Thank you very much for pointing it out. As always, I appreciate your help.

 

Not sure how I missed your previous post though I was digging for sometime, I must be searching just by the error message.

 

If I can ask one more thing, I was trying to do same queries to CCX API, I see it returns response in XML format like the one copied below. Is there a way to make CCX return JSON objects or the script convert XML to JSON? Or the only way to go will be with XML and XPath?

 

TEXT[{\"@type\":\"teamXMLList\",\"team\":[{\"self\":\"https://uccx12pub.lab.com/adminapi/team/1\",\"teamId\":1,\"teamname\":\"Default\"}]}]

Try sending this header in your request:

Accept: application/json

;)

Thank you, Anthony. That worked to get response from CCX API in JSON format in Postman.

I also realize the expression that I was using against Admin API was incorrect, it had to be changed from "$.team.teamname" > "$.team[0].teamname" to get the value. Testing it first in Jayway parser helped here.

I have response of string type which look like this, i got it from 'Make rest call'
 
U "{\"count\":1,\"next\":null,\"previous\":null,\"results\":[{\"id\":1,\"url\":\"http://xx.xx.xx.xx:xxxx/api/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 to such string, checked with other tools like postman other service provides response with valid json),

My requirement is to get the 'name' parameter from it which is inside the 'results' array.
I need to set the name parameter value in different String type variable. lets assume variable name as 'newName'.

Saw few post , suggesting to perform 'Create Json Document' on response string , not able to understand this step, can you give your input.

Thanks in advance.

I posted a screenshot of the create JSON document step based on the result from the make REST call step that is stored in a string variable.

https://community.cisco.com/t5/contact-center/json-path-using-variable/m-p/4799131/highlight/true#M126501

Did that not work for you?



Response Signature


thanks for directing me to correct post . it really helped.

@Roger Kallberg I need your help here,
I need to make rest call from uccx script in , that call is for Oauth .
I need to make a post call , in that call need to pass body as 'x-www-form-urlencoded' in headers and in body the credentials details
i did the same in uccx script but it is not working 
First I created the string and all parameters and added that parameter in body .
Attached the scrrenshot for reference , take a look and help me out here.
Thanks in advance.

Sorry, but I don't have the faintest on how to do that. Have you looked over at DevNet to see if you find anything related to this?



Response Signature


I can see your screenshot getting the null value that is why getting this error.