cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to fail a Snap for Invalid json as i/p doc(Duplicate keys)

KumarR
New Contributor

Hi Team,
I am sending a invalid json payload from the postman to my pipeline.
The pipeline has first snap as Copy, when i checked the output of copy it has removed duplicated keys from the invalid json payload. My expectation was that it will throw error as i have sent invalid json.
Any thought on how can i fail the pipeline if the payload coming as invalid json into pipeline/snap?
Below was payload i sent to pipe from postman tool-
{
โ€œwwwโ€: {
โ€œstationโ€: โ€œ3333โ€,
โ€œstationโ€: โ€œ22222โ€,
โ€œstationโ€: โ€œ44444โ€,
โ€œddโ€: 24224,
โ€œdd1โ€: โ€œ34224โ€,
โ€œdd2โ€: โ€œsfsfโ€,
โ€œdd3โ€: โ€œdddsfsfโ€
}
}

The output of copy snap came as below(i wannt the snap to be failed as it was invalid json data)-
{
โ€œwwwโ€: {
โ€œstationโ€: โ€œ44444โ€,
โ€œscaleIdโ€: โ€œwrwrโ€,
โ€œddโ€: 24224,
โ€œdd1โ€: โ€œ34224โ€,
โ€œdd2โ€: โ€œsfsfโ€,
โ€œdd3โ€: โ€œdddsfsfโ€
}
}

Thanks,
Kumar R

7 REPLIES 7

tstack
Former Employee

Most (all?) JSON parsers donโ€™t consider duplicate keys as a problem. Why are you concerned about this?

I think youโ€™ll find that other errors, like non-terminated strings, missing curly braces, and other syntax errors will be flagged correctly.

KumarR
New Contributor

Hi Tim,
Yes other errors like non-terminated strings are giving proper validation erros.
Concern for dup key is because our testing team has this scenario of sending invalid json for the automation testing and they want this case to be failed, but as dup key is not problem for most of snaps so they will get success response. Testing team will expect invalid json error for this but getting success.

We have test pattern in all interfaces for all tools. As apigee and tibco have solution for this.
Apigee has policy regExp and tibco parser has Staxon function for json parsers, so i am looking for similar option in snaps.
Please let me know any thoughts to validate this invalid json due to dup keys.

With Regards,
KumarR

KumarR
New Contributor

Hi Team,
Below workaround i did to using Python script to validate invalid json -
1-Have binary to doc snap as first snap and land i/p as encodedBase64
2-Add next snap as Script snap with python lang.
Decode back the i/p doc in script and use json.loads module for parsing json it will raise error on dup key.
Refer below link for script-

Thanks,
Kumar