cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1078
Views
25
Helpful
3
Replies

CVP rest json response parsing

Deep46
Level 1
Level 1

Hi ,

 

I have been trying to parse a json response in the CVP call studio 12.5.1

 

The response is as below :

 

{
"first": {
"details": [
{
"Number": "123456"
"contactname": "John"
"Application": ""
}
]
}
"taxID": null
"requestnum": "abcdef-72e1-11ec-bcb0-003400bcab81"
"links": {
"selfnone": "/care/cm/cach/first/123456/details"
"notestext": "/care/cm/cach/first/123456/notes"
"auditing": "/care/cm/cach/first/123456/audit"
}
}

 

I tried to extract contactname using the below expression in Set value element :

 

importPackage(com.audium.server.cvpUtil);
var val={Data.Element.query_test.response_body};
var path="$.first.details.contactname";
JSONPathUtil.eval(val,path);

 

When i debug the call studio project  , i get the exception. I have set the response body in the previous element name query_test and could see the value in the logs as well.

 

I could not get any value of contactname from the above expression. Can anyone guide if they have suggestions .

 

@janinegraves 

1 Accepted Solution

Accepted Solutions

janinegraves
Spotlight
Spotlight
I think the syntax error came from your copying the JSON string from the
activity log, which omits commas - making your json string show as invalid.

I fixed it by adding the commas to get this (see below). Then was able
to use jsonpathfinder.com to provide the jsonpath string to use:
x.first.details[0].contactname

So if you replace the x with $, you should be able to change your path
to "$.first.details[0].contactname" and it'll work.


Your 'repaired' JSON value is really this:

{
    "first": {
        "details": [
            {
                "Number": "123456",
                "contactname": "John",
                "Application": ""
            }
        ]
    },
    "taxID": null,
    "requestnum": "abcdef-72e1-11ec-bcb0-003400bcab81",
    "links": {
        "selfnone": "/care/cm/cach/first/123456/details",
        "notestext": "/care/cm/cach/first/123456/notes",
        "auditing": "/care/cm/cach/first/123456/audit"
    }
}

View solution in original post

3 Replies 3

janinegraves
Spotlight
Spotlight
I think the syntax error came from your copying the JSON string from the
activity log, which omits commas - making your json string show as invalid.

I fixed it by adding the commas to get this (see below). Then was able
to use jsonpathfinder.com to provide the jsonpath string to use:
x.first.details[0].contactname

So if you replace the x with $, you should be able to change your path
to "$.first.details[0].contactname" and it'll work.


Your 'repaired' JSON value is really this:

{
    "first": {
        "details": [
            {
                "Number": "123456",
                "contactname": "John",
                "Application": ""
            }
        ]
    },
    "taxID": null,
    "requestnum": "abcdef-72e1-11ec-bcb0-003400bcab81",
    "links": {
        "selfnone": "/care/cm/cach/first/123456/details",
        "notestext": "/care/cm/cach/first/123456/notes",
        "auditing": "/care/cm/cach/first/123456/audit"
    }
}

Just noticed it says "Rising star" next to Janine's name. Who do we have to petition to have that changed to "Geostationary Orbit"?

Deep46
Level 1
Level 1

 Thanks for showing us that we can use jsonpathfinder to get this syntax !   It worked ! Thanks a lot @janinegraves  .