JSON validation and detect unexpected elements

Hi,

APIGEE Version: 4.19.06.00

I have a requirement to validate the incoming JSON request body and to reject if the request contains any unexpected element in the JSON.

eg expected request:

{"Fname":""",Lname":""",Age":""}

And I should reject if the request contains any unexpected elements (CardNumber) like below:

{"Fname":""",Lname":""",Age":"","CardNumber":""}

The example I quote above is just a simple json request and the actual JSON request is more complex containing many elements, arrays etc.

Is there any simple way to do this in APIGEE to ensure the request JSON message is as expected before processing to downstream system?

Note: I have already referred the article https://community.apigee.com/articles/42993/using-the-openapi-spec-to-validate-json-requests.html and is looking for any alternate solutions available here.

Solved Solved
0 3 858
1 ACCEPTED SOLUTION

Yes, JSON schema validation has been a sort of "evolving" area of interest. The JSON schema standard itself seemed to be a moving target, never finalized. As a result, Apigee never had a firm foundation on which to build a supported policy that would do what you want.

Apigee is now working on a builtin policy that will perform validation of requests against an OpenAPI Specification. That is nice to know but won't help you in the short term.

In the past, people have used external systems. You can do schema validation in JavaScript, or you can rely on a Java callout.

Here's one:

https://github.com/DinoChiesa/ApigeeEdge-Java-Validate-JSON-Schema

It may work for your purposes.

View solution in original post

3 REPLIES 3

Yes, JSON schema validation has been a sort of "evolving" area of interest. The JSON schema standard itself seemed to be a moving target, never finalized. As a result, Apigee never had a firm foundation on which to build a supported policy that would do what you want.

Apigee is now working on a builtin policy that will perform validation of requests against an OpenAPI Specification. That is nice to know but won't help you in the short term.

In the past, people have used external systems. You can do schema validation in JavaScript, or you can rely on a Java callout.

Here's one:

https://github.com/DinoChiesa/ApigeeEdge-Java-Validate-JSON-Schema

It may work for your purposes.

Thanks Dino for the details.

I provided an updated solution that supports OAS 2 and 3 which detects additional properties here: https://community.apigee.com/articles/88441/validate-json-requests-using-openapi-spec-20-or-30.html