Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
root
Creator II
Creator II

[resolved] JSON Payload - Validate

I have a simple webservice setup.

tRestRequest --> tExtractJSONFields --> my processing code --> tXMLMap --> tRestResponse

It works perfectly fine. However, one missing chunk is how to validate the input JSON payload (POST in my case) and send back an error HTTP code like 400 back to the client?

Is there any direct way to validate the JSON document being sent which has all the relevant fields? What are the best practices which one can follow to design the job?
Labels (5)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi
Here is my idea: validate all of fields on a tJavaRow and then trigger different processing based on the validation result, eg:
tRestRequest --> tExtractJSONFields -->main--tJavaRow--runIf1---tfixedFlowInput--main--my processing code...tRestResponse1
                                                                                   --runIf2---tfixedFlowInput--main--tXMLMap--...tRestResponse2

on tJavaRow:
if(..multiple validation condition..){
global.put("isValid",true);
context.columnName=input_row.columName;
context.otherColumnName=input_row.otherColumnName;
}else{
global.put("isValid",false);
}

set the condition of runIf1 as:
(Boolean)globalMap.get("isValid")

set the condition of runIf2 as:
!(Boolean)globalMap.get("isValid")

tfixedFlowInput: generate the current row with context variables.

Regards
Shong

View solution in original post

2 Replies
Anonymous
Not applicable

Hi
Here is my idea: validate all of fields on a tJavaRow and then trigger different processing based on the validation result, eg:
tRestRequest --> tExtractJSONFields -->main--tJavaRow--runIf1---tfixedFlowInput--main--my processing code...tRestResponse1
                                                                                   --runIf2---tfixedFlowInput--main--tXMLMap--...tRestResponse2

on tJavaRow:
if(..multiple validation condition..){
global.put("isValid",true);
context.columnName=input_row.columName;
context.otherColumnName=input_row.otherColumnName;
}else{
global.put("isValid",false);
}

set the condition of runIf1 as:
(Boolean)globalMap.get("isValid")

set the condition of runIf2 as:
!(Boolean)globalMap.get("isValid")

tfixedFlowInput: generate the current row with context variables.

Regards
Shong
root
Creator II
Creator II
Author

shong wrote:
Hi
Here is my idea: validate all of fields on a tJavaRow and then trigger different processing based on the validation result, eg:
tRestRequest --> tExtractJSONFields -->main--tJavaRow--runIf1---tfixedFlowInput--main--my processing code...tRestResponse1
                                                                                   --runIf2---tfixedFlowInput--main--tXMLMap--...tRestResponse2

on tJavaRow:
if(..multiple validation condition..){
global.put("isValid",true);
context.columnName=input_row.columName;
context.otherColumnName=input_row.otherColumnName;
}else{
global.put("isValid",false);
}

set the condition of runIf1 as:
(Boolean)globalMap.get("isValid")

set the condition of runIf2 as:
!(Boolean)globalMap.get("isValid")

tfixedFlowInput: generate the current row with context variables.

Regards
Shong

This is great. I tried, it works. I was actually expecting a way in which a JSON document could be validated directly on a schema or something... but, again, this works. Thanks.