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

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.
View all posts by Sandro Pereira

Azure Function: JSON Schema Validation (new release)

Azure Function: JSON Schema Validation (new release)

We just released a new version of our Azure Function JSON Schema Validation, adding support for more complex schema validations. In this case, we add support for applying subschemas validation conditionally.

The ifthen and else keywords allow the application of a subschema based on the outcome of another schema, much like the if/then/else constructs you’ve probably seen in traditional programming languages.

  • If if is valid, then must also be valid (and else is ignored.) If if is invalid, else must also be valid (and then is ignored).
  • If then or else is not defined, if behaves as if they have a value of true.
  • If then and/or else appear in a schema without ifthen and else are ignored.

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": {
        "address": [
            {
                "contact": {
                    "firstName": "myFirstName",
                    "lastName": "myLastName"
                },
                "type": "bill"
            }
        ]
    },
    "jsonSchema": {
        "type": "object",
        "properties": {
            "address": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "contact": {
                            "type": "object",
                            "properties": {
                                "firstName": {
                                    "type": "string"
                                },
                                "lastName": {
                                    "type": "string"
                                }
                            },
                            "required": []
                        },
                        "type": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "contact",
                        "type"
                    ]
                }
            }
        },
        "if": {
            "properties": {
                "address": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "type": {
                                "const": "bill"
                            }
                        }
                    }
                }
            }
        },
        "then": {
            "properties": {
                "address": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "contact": {
                                "required": [
                                    "firstName"
                                ],
                                "properties": {
                                    "firstName": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "else": {
            "properties": {
                "address": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "contact": {
                                "required": [],
                                "properties": {}
                            }
                        }
                    }
                }
            }
        }
    }
}

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:

Download JSON Schema Validation Azure Function

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 member Luís Rigueira for 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.
View all posts by Sandro Pereira

Azure Function: JSON Schema Validation

Azure Function: JSON Schema Validation

JSON Schema is a declarative language that allows you to annotate. It provides a format for what JSON data is required for a given application and how to interact with it and validate JSON documents to ensure it meets the requirements.

Applying JSON Schemas validation in your solutions will let you enforce consistency and data validity across similar JSON data.

If you are not familiar with JSON Schema, you will then notice that the JSON Schema itself is written in JSON-based format. It’s just a declarative format for “describing the structure of other data”. This is both its strength and its weakness (which it shares with other similar schema languages). It is easy to concisely describe the surface structure of data, and automate validating data against it. However, since a JSON Schema can’t contain arbitrary code, certain constraints exist on the relationships between data elements that can’t be expressed. JSON Schema is a proposed IETF standard.

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": {
        "name": "",
        "extension": "xml"
    },
    "jsonSchema": {
        "type": "object",
        "properties": {
            "name": {
                "type": "string",
                "pattern": "^.*[a-zA-Z0-9]+.*$"
            },
            "extension": {
                "type": "string"
            }
        }
    }

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 member Diogo Formosinho for testing and helping me develop this function with me!

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.
View all posts by Sandro Pereira

JSON Validator Tool

JSON Validator Tool

Another common task for us developers inside Azure Integration Services, especially inside Logic Apps, is manually creating a JSON message, either inside a Parse JSON action, Compose action, or directly in the connectors (or any other way), but there is a catch…

If you work in the Azure Portal and create an invalid JSON message inside an action or connector, the editor will not allow you to save the Logic App. Instead, it will give you an error saying that the definition contains invalid parameters.

However, if you are creating the same Logic App Consumption inside Visual Studio:

We can successfully validate this Logic App:

And we can actually successfully deploy this Logic App:

And that will become a problem once we run our Logic App. For this reason, it is always good for you to guarantee that the JSON message is well formatted before you deploy your business processes.

And yes, I know many only tools exist to perform this task, so why a Windows tool? Again, for the same reasons I described in my previous tools: security and privacy

I’m starting to become a freak in terms of security. Nothing is free, and the problem with these online tools is that we never know behind the scenes what they are doing. Are you sure that they are not keeping logs of the inputs we provide and the result outputs? And don’t say, but Sandro, this is just a simple message. Well, many messages have sensitive (private) information from users or companies that sometimes you are not aware of, so it is better to play safe than sorry. It is wise to be careful now so that problems do not occur later on and protect yourself against risk rather than be careless.

JSON Validator Tool

JSON Validator Tool is a lightweight Windows tool that allows you to validate and reformat a JSON message.

To not raise the same suspicions about this tool, the source code is available on GitHub!

Download

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

Credits

  • Diogo Formosinho | Member of my team and one of the persons responsible for developing this tool.
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.
View all posts by Sandro Pereira