Azure Function: JSON Schema Validation (new release v3.0)

We just released another version of our Azure Function JSON Schema Validation, adding support to another feature. In this case, a very basic one, required fields.

In order to specify the mandatory properties or elements, we need to use the required keyword, where you can specify a list of strings that need to be present as key names in the list of key:value pairs that appear in a JSON document. Each of these strings must be unique.

JSON Schema Validation Function

The JSON Schema Validation is a simple Azure Function that allows you to validate your JSON message against a JSON Schema, enabling you to specify constraints on the structure of instance data to ensure it meets the requirements.

The function receives a JSON payload with two properties:

  • The JSON message in the json property.
  • And the JSON Schema in the jsonSchema property.

Example:

{
  "json": {
	"city": "Porto",
    "name": "Sandro"
},
  "jsonSchema": {
    "properties": {
        "city": {
            "type": "string"
        },
        "name": {
            "type": "string",
            "pattern":"^.*[a-zA-Z0-9]+.*$"
        }
    },
    "type": "object",
    "required": ["name"]
   }
}

The function’s output will be:

  • A 200 OK if the JSON message is valid.
  • Or a 400 Bad Request if there are validation errors/issues.

Where can I download it?

You can download the complete Azure Functions source code here:

Hope you find this helpful! So, if you liked the content or found it helpful and want to help me write more content, you can buy (or help buy) my son a Star Wars Lego! 

Big thanks to my team members Luís Rigueira and Diogo Formosinho for testing and adding this new feature.

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top