how to validating json Structure sending to API ?

how to validating json Structure sending to API ?

  

i am using structure to recieve the json data if the structure like below 

{

"name":"panki",

"age":"23"

but for the below json i need to get error message but the response is success why.

{

"name":"panki",

"age":"23"

}sadfashgdvh


please help me

Hi Santhu,

What are you using to receive/parse the JSON? Is this a REST service, or are you using JSON Deserialize?

Kilian Hekhuis wrote:

Hi Santhu,

What are you using to receive/parse the JSON? Is this a REST service, or are you using JSON Deserialize?

hi kilian  


iam using structure to recieve the json data.(structure contain name and age attributes).

no iam not using JSON Deserialize.


Hi Santhu,

Again, what do you mean by "receiving"? Are we talking REST API here? If not, and you're not using JSON Deserialize, what are you using?

Kilian Hekhuis wrote:

Hi Santhu,

Again, what do you mean by "receiving"? Are we talking REST API here? If not, and you're not using JSON Deserialize, what are you using?

hi kilian 

i am using post method so accepting the json sent by the user..yes we are talking about rest api.



Hi Santhu,

I would assume that any trailing characters after the closing curly brace are just ignored. If you really must flag an error (but why would you?), you'll need to add an On Request handler that checks for this situation.

Kilian Hekhuis wrote:

Hi Santhu,

I would assume that any trailing characters after the closing curly brace are just ignored. If you really must flag an error (but why would you?), you'll need to add an On Request handler that checks for this situation.

hi kilian 

thank you for replaying me and i dont know how to use on Request .could you please guid me.


Hi Santhu,

To add an On Request handler, click the Exposed REST API in the tree, and refer to the Properties window. There, you'll find (below the "Advanced" header), the "On Request" Property. Use the dropdown to select "New OnRequest". After clicking this, you'll have, below the REST API in the tree, an OnRequest Action. When you open it, you see that you have a Request Input Parameter (of type HTTPRequest) with a RequestText Attribute. This Attribute contains the full body of the request. You can check it for whatever you like, and raise an Exception if it's not something you like.

Kilian Hekhuis wrote:

Hi Santhu,

To add an On Request handler, click the Exposed REST API in the tree, and refer to the Properties window. There, you'll find (below the "Advanced" header), the "On Request" Property. Use the dropdown to select "New OnRequest". After clicking this, you'll have, below the REST API in the tree, an OnRequest Action. When you open it, you see that you have a Request Input Parameter (of type HTTPRequest) with a RequestText Attribute. This Attribute contains the full body of the request. You can check it for whatever you like, and raise an Exception if it's not something you like.

hi kilian 

thank you for replaying me.. I tried a lot i did'nt get any logic to throw an error.


Did you try to throw an Exception? If that doesn't work, perhaps you can use SetStatusCode from the HTTPRequestHandler Extension (note I haven't tried that myself).

However, I still think it's weird you want to detect this very rare situation that really shouldn't happen, and that you can handle fine by just ignoring it (as the Platform does).

Interesting, I just tested it and it is indeed ignoring content after a valid json string.

Pretty sure It's something done internally by the Web API framework. I implemented most of the structures deserialization for REST and I'm sure the platform doesn't do any explicit manipulation at that level.


Probably could look if there was a way to prevent it from ignoring the trailing text

But like Kilian said I also can't think of any good reason for actually want to throw an error on that situation, so I think I prefer to keep the current platform behavior.


Regards,
João Rosado

Kilian Hekhuis wrote:

Did you try to throw an Exception? If that doesn't work, perhaps you can use SetStatusCode from the HTTPRequestHandler Extension (note I haven't tried that myself).

However, I still think it's weird you want to detect this very rare situation that really shouldn't happen, and that you can handle fine by just ignoring it (as the Platform does).


hi kilian 

sorry for late replay.thank you for replaying me..the requirement demanding to detect that extra text.  

João Rosado wrote:


Probably could look if there was a way to prevent it from ignoring the trailing text



Regards,
João Rosado

hi João Rosado

we can't detect that. i need a logic  to over come this issue and iam trying.

Can you tell us the reason behind your requirement?


What I meant on my post was actually "We on the OutSystems Platform could probably could look if there was a way to prevent it from ignoring the trailing text.". But without a really good reason /use case even if I add it as a bug or change request to the backlog it will be classified with really low priority and never get done.


Regards,

João Rosado

Hi Santhu,

That seems like a very, very silly requirement. You should go back to whomever wrote that requirement, and ask them why it's in there. Also, you could say that OutSystems just doesn't support that.

That said, did you check what I wrote about throwing an Exception or setting the status code?

Kilian Hekhuis wrote:

Hi Santhu,

That seems like a very, very silly requirement. You should go back to whomever wrote that requirement, and ask them why it's in there. Also, you could say that OutSystems just doesn't support that.

That said, did you check what I wrote about throwing an Exception or setting the status code?

hi kilian 

yeh! i checked  throwing an Exception and  setting the status code..throwing an exception is working but we need an IF statement to show the path to exception.


João Rosado wrote:

Can you tell us the reason behind your requirement?


What I meant on my post was actually "We on the OutSystems Platform could probably could look if there was a way to prevent it from ignoring the trailing text.". But without a really good reason /use case even if I add it as a bug or change request to the backlog it will be classified with really low priority and never get done.


Regards,

João Rosado

hi  João Rosado


thank you for responding. problem is if we Use On Request method in an API and if we further want to manupulate  the Json in on request using RequestText then the problem may arise.

Other option is to change the input parameter on the API to be simple TEXT. Then in your code you can deserialize the JSON yourself using JSONDeserialize or by manualy deserializing the string if you realy want to go that far.. 

Solution

Sure, you could, you could even not use OutSystems at all, but that's not why we're here, isn't it? The "requirement" that Santhu has is a very, very strange one, and he'd be better off telling their boss it's not easily possible with OutSystems, than to blindingly follow the "requirement" on that.

Solution

Kilian Hekhuis wrote:

Sure, you could, you could even not use OutSystems at all, but that's not why we're here, isn't it? The "requirement" that Santhu has is a very, very strange one, and he'd be better off telling their boss it's not easily possible with OutSystems, than to blindingly follow the "requirement" on that.

hi kilian 

thank you for replaying me.and sorry for late replay.


 I convinced them by explaining what you told.


John Williams wrote:

Other option is to change the input parameter on the API to be simple TEXT. Then in your code you can deserialize the JSON yourself using JSONDeserialize or by manualy deserializing the string if you realy want to go that far.. 

hi john 

thank you for your suggestion..but they are not allowing   text  format.


Hi Santhu,

Great to hear you could convince them :). Happy coding!