Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
fabienb1
Contributor III
Contributor III

Parsing Json from webhook in Talend Cloud

Hello,

I am trying to set up a job trigerred by a webhook, and I am having trouble parsing the body of the request I'm sending to the job.

The body I am sending to the job looks like this :

0695b00000fHXrGAAW.png

And my resource_webhook_payload variable look like this :

tLogRow_2 - Content of row 1: [{"data":"{"testKey1" : "test1" ,"testKey2" : "test2"}","type":"application/json"}]

We can see that there are now double-quotes surrounding the json body. I am then trying to parse each json keys, but I am failing to do so because of these double-quotes : when using tExtractJsonFields, I am getting the error

tExtractJSONFields_1 - Cannot determine next state.

When I escape the double-quotes in my request by using "\", I am able to parse the body properly :

0695b00000fHXs4AAG.png

However, I would like to be able to parse the request without having to escape every double-quotes in the request body.

Does anyone know the proper way to parse the

resource_webhook_payload variable ?

Thank you !

Labels (3)
4 Replies
Anonymous
Not applicable

Hi

It is an invalid json format for tExtractJsonFields component parsing, try to add escape char "\" to the string before tExtractJsonFields in the job. eg:

....tJavaRow--main--tExtractJsonFields

 

on tJavaRow:

output_row.columnName=input_row.columnName.replace("\"testKey1\"","\\\"testKey1\\\"").replace("\"testKey2\"","\\\"testKey2\\\"");

 

Regards

Shong

fabienb1
Contributor III
Contributor III
Author

Hello,

 

Thank you for your reply.

However, do you know if there is another way to parse the resource_webhook_payload without having to manually escape the double-quotes ?

The json body I am sending initially is properly formated, for example :

{

        "testKey1": "testValue1",

        "testKey2": "testValue2"

}

So I would like to be able to use this directly, without having to manually remove the double-quotes.

 

Thank you,

Anonymous
Not applicable

If you don't escape or remove the double-quotes, it is in invalid json string, tExtractJsonField can't parse it. I'm afraid what you can do is to remove the double-quotes if there are double-quotes surrounding the json body in the job.

 

 

CMathisUp
Partner - Contributor
Partner - Contributor

Hello,

 

I'm quite interested in the webhook solution to trigger some jobs.

Though, I could not understand from the documentation how I should implement the job to read from the resource_webhook_payload. How should a job look like for such implementation ? What component should I use to read from the webhook ?