Post Closed
184
Views
4
Comments
API validation to check Attributes present or not ?
Question


as below json shows the request giving to API,i need to validate this json as each fields should present if not  i have to give the response back  as the attribute names (for ex: if  "name" and "age" fields are missing i have to give response as {"error": "name ,age filds are missing "} )

 please help me

{

"name":"samsa",

"age":21,

"address":"xyz",

"pincode":51342

}

2026-01-26 10-25-31
Lennart Kraak
Champion

Hi Santhu,

If this these are record values that you receive, you can just check in the record if these fields are empty. Otherwise you can deserialize the JSON to a record and check the values that way.

Regards,

Lennart

UserImage.jpg
Sridhar Sivaprakasam

santhu MS wrote:


as below json shows the request giving to API,i need to validate this json as each fields should present if not  i have to give the response back  as the attribute names (for ex: if  "name" and "age" fields are missing i have to give response as {"error": "name ,age filds are missing "} )

 please help me

{

"name":"samsa",

"age":21,

"address":"xyz",

"pincode":51342

}

Hi Santhu,

You can use JSONDeserialize to parse the JSON string and check for the validity of as many fields and send a error response back to the consumer with error message.

something like below..

Sridhar. S


2018-10-29 08-31-03
João Marques
 
MVP

Isn't this a duplicate of this one?

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Yes it is. I'm closing this one.