[resolved] JSON Payload - Validate

Highlighted
Eight Stars

[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?

Accepted Solutions
Highlighted
Community Manager

Re: [resolved] JSON Payload - Validate

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
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post


All Replies
Highlighted
Community Manager

Re: [resolved] JSON Payload - Validate

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
----------------------------------------------------------
Talend | Data Agility for Modern Business

View solution in original post

Highlighted
Eight Stars

Re: [resolved] JSON Payload - Validate

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.

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Talend API Designer – Technical Overview

Take a look at this technical overview video of Talend API Designer

Watch Now

Getting Started with APIs

Find out how to get started with APIs

Read