Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
François_T
Contributor
Contributor

How can I parse the webhook payload json data ?

Hello !

I'm trying to read the data sent to a job using the webhook URL. I see that I'm getting the payload as a json array, where I have the "data" field containing what I need.

but what I don't know how to do is :

-how can i parse this json content ? I see Json components, but based on fields or files, and I don't know how to convert my context to one of those

-once I will have this data value, how can I decode it ? It's a simple base64 encoding, so I guess a simple tjava or tjavarow, with the right function ?

Thanks in advance for any help 🙂

Labels (3)
6 Replies
François_T
Contributor
Contributor
Author

I tried with a simple tjava component, with this code :

 

JSONObject obj=new JSONObject(context.resource_webhook_payload);

context.email_requester=obj.getString("data");

 

but it's refusing to read the json object, as there are "[]" around it. How can I read the content ?

Anonymous
Not applicable

@François Tissandier​ , take a look at this topic, and try the code used to decode the base64 string on tJavaRow.

 

Regards

Shong

François_T
Contributor
Contributor
Author

Thanks for the answer ! But before being able to decode anything, I need to have the value first 🙂

ANd "context.resource_webhook_payload" contains the json payload, but with [ ] around it. So "new JSONObject(" isn't working. How can I make it read the Json part within the [ ] ?

Anonymous
Not applicable

@François Tissandier​ , ​remove the [ ] from the string using expression:

JSONObject obj=new JSONObject((context.resource_webhook_payload.replaceAll("[","")).replaceAll("]",""));

 

 

François_T
Contributor
Contributor
Author

Indeed, quite simple and it's working !

 

Is it possible to decode the base64 content ? I can't find a simple way to do it in my tjava component 😞

Anonymous
Not applicable

if the data comes from an input component, use tJavaRow instead of tJava, as showed in the topic.