Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For more details see here: JSON Schema .

PIPEFORCE provides built-in toolings for storage, resolving and validation using JSON Schemas.

Store a JSON Schema in the Property Store

By default, a JSON schema which describes a JSON object (= document) within PIPEORCE is placed in a property with content type application/json in the property store using this property path:

Code Block
global/app/<APP>/object/<NAME>/v1/schema

Where <APP> is the name of the app, the object belongs to. <NAME> is the name of the object. In the example of a person which is part of the app myappp, you could use this path to access the object schema in a unique way from within the overall PIPEFORCE instance:

Code Block
global/app/myapp/object/person/v1/schema

Validate a JSON document

In order to validate whether a given JSON document complies with such a given JSON schema, you can use the command json.validate. This command will by default check whether a given document is a valid JSON document (= syntax validation). Additionally, a JSON Schema can be defined which should be loaded and used as based for schema validation (= structural validation).

This example will validate a JSON given in the body using the JSON schema from above which is now stored in the property store:

Code Block
languageyaml
body: {
    "firstName": "Sam",
    "lastName": "Meyer",
    "age": 48,
    "gender": "male"
  }
  
pipeline:
  - json.validate:
      schema: $uri:global/app/myapp/object/person/v1/schema

In case the given JSON document is valid and complies with the JSON schema rules, OK is returned:

Code Block
languagejson
{
    "status": "ok",
    "statusCode": 200
}

Let’s change the value of field age now to a string value (in line 4) instead and validate again.

Code Block
languageyaml
body: {
    "firstName": "Sam",
    "lastName": "Meyer",
    "age": "48",
    "gender": "male"
  }
  
pipeline:
  - json.validate:
      schema: $uri:global/app/myapp/object/person/v1/schema

This will return an validation error like this:

Code Block
languagejson
{
    "status": "error",
    "statusCode": 200,
    "statusMessage": [
        {
            "type": "type",
            "path": "$.age",
            "message": "$.age: string found, number expected"
        }
    ]
}