1
votes

Im getting a few errors in while validaing JSON. Im unable to understand the errors can anyone help and explain a bit.

{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Modified JSON Schema draft v4 that includes the optional '$ref' and 'format'",
"definitions": {
    "schemaArray": {
        "type": "array",
        "minItems": 1,
        "items": { "$ref": "#" }
    },
    "positiveInteger": {
        "type": "integer",
        "minimum": 0
    },
    "positiveIntegerDefault0": {
        "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
    },
    "simpleTypes": {
        "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
    },
    "stringArray": {
        "type": "array",
        "items": { "type": "string" },
        "minItems": 1,
        "uniqueItems": true
    }
},
"type": "object",
"properties": {
    "id": {
        "type": "string",
        "format": "uri"
    },
    "$schema": {
        "type": "string",
        "format": "uri"
    },
    "$ref": {
        "type": "string"
    },
    "format": {
        "type": "string"
    },
    "title": {
        "type": "string"
    },
    "description": {
        "type": "string"
    },
    "default": { },
    "multipleOf": {
        "type": "number",
        "minimum": 0,
        "exclusiveMinimum": true
    },
    "maximum": {
        "type": "number"
    },
    "exclusiveMaximum": {
        "type": "boolean",
        "default": false
    },
    "minimum": {
        "type": "number"
    },
    "exclusiveMinimum": {
        "type": "boolean",
        "default": false
    },
    "maxLength": { "$ref": "#/definitions/positiveInteger" },
    "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
    "pattern": {
        "type": "string",
        "format": "regex"
    },
    "additionalItems": {
        "anyOf": [
            { "type": "boolean" },
            { "$ref": "#" }
        ],
        "default": { }
    },
    "items": {
        "anyOf": [
            { "$ref": "#" },
            { "$ref": "#/definitions/schemaArray" }
        ],
        "default": { }
    },
    "maxItems": { "$ref": "#/definitions/positiveInteger" },
    "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
    "uniqueItems": {
        "type": "boolean",
        "default": false
    },
    "maxProperties": { "$ref": "#/definitions/positiveInteger" },
    "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
    "required": { "$ref": "#/definitions/stringArray" },
    "additionalProperties": {
        "anyOf": [
            { "type": "boolean" },
            { "$ref": "#" }
        ],
        "default": { }
    },
    "definitions": {
        "type": "object",
        "additionalProperties": { "$ref": "#" },
        "default": { }
    },
    "properties": {
        "type": "object",
        "additionalProperties": { "$ref": "#" },
        "default": { }
    },
    "patternProperties": {
        "type": "object",
        "additionalProperties": { "$ref": "#" },
        "default": { }
    },
    "dependencies": {
        "type": "object",
        "additionalProperties": {
            "anyOf": [
                { "$ref": "#" },
                { "$ref": "#/definitions/stringArray" }
            ]
        }
    },
    "enum": {
        "type": "array",
        "minItems": 1,
        "uniqueItems": true
    },
    "type": {
        "anyOf": [
            { "$ref": "#/definitions/simpleTypes" },
            {
                "type": "array",
                "items": { "$ref": "#/definitions/simpleTypes" },
                "minItems": 1,
                "uniqueItems": true
            }
        ]
    },
    "allOf": { "$ref": "#/definitions/schemaArray" },
    "anyOf": { "$ref": "#/definitions/schemaArray" },
    "oneOf": { "$ref": "#/definitions/schemaArray" },
    "not": { "$ref": "#" }
},
"dependencies": {
    "exclusiveMaximum": [ "maximum" ],
    "exclusiveMinimum": [ "minimum" ]
},
"default": { }

}

And here is the json.

{
  "type": "identification.carrier",
  "id": "uui#abb0ef56-8562-4056-aa62-afb758a150ad",
  "happened": "2018-03-28T10:52:44.35+02:00",
  "processed": "2018-03-28T10:52:44.35+02:00",
  "tracking_id": "tid#ad2ebdb1-5d5b-4dcb-a058-494b6af89127",
  "source_attributes": {
    "id": "idsadm@app44A0",
    "data": {
      "info": "resumeIdentify: result: carrier has operator and mobile network",
      "callId": "ad2ebdb1-5d5b-4dcb-a058-494b6af89127",
      "contextId": "0aeb6745-a43c-4257-a535-6905d21a5297",
      "ids_state": "SUCCESS",
      "ids_strategy_type": "REDIRECT_MULTI_WITH_MSISDN_IN_HEADER",
      "ids_identity_type": "MSISDN",
      "country": "DE",
      "ids_result_type": "IDENTITY",
      "ids_result_network": "MobileNetwork[MOBILE=Vodafone D2 GmbH,operator=Operator[ref=10013,MNO=VODAFONE,countryIsoName=DE],countryIsoName=DE,ref=64,mnc=2,mcc=262,mvnos=[Operator[ref=30,MVNO=MOBILCOM-DEBITEL,countryIsoName=DE]]",
      "idsServiceLine": "599 387 240"
    }
  },
  "event_data": {
    "service": {
      "name": "IdsService",
      "version": "4.1"
    },
    "result": {
      "country": "DE",
      "mno": "VODAFONE",
      "mvno": "MOBILCOM-DEBITEL",
      "mcc": "262",
      "mnc": "2"
    }
  }
}

Message: JSON does not match any schemas from 'anyOf'. Schema path:

/properties/type/anyOf

Message: Invalid type. Expected Array but got String. Schema path:

/properties/type/anyOf/1/type

Message: Value "identification.carrier" is not defined in enum. Schema path:

/definitions/simpleTypes/enum

Message: String 'uui#abb0ef56-8562-4056-aa62-afb758a150ad' does not validate against format 'uri'. Schema path:

/properties/id/format

2
Are you saying you do not know how to read the errors or that you do not know JSON Schema? Did you make the schema and JSON?Relequestual

2 Answers

2
votes

The schema provided is a slightly modified meta-schema, it validates JSON schema structure.

The JSON data provided looks more like a DTO, not a schema. Therefore you receive an error about wrong type.

JSON schema type MUST be single value or array of such strings: "array","boolean","integer","null","number","object","string".

"identification.carrier" is not in the list that's why you get validation error.

Most likely you should validate your data against a particular schema (not meta-schema), something like (majority of properties are omitted for simplicity):

{
  "type": "object",
  "properties": {
    "type": {"type":"string"},
    "id": {"type": "string"},
    "happened": {"type":"string", "format":"date-time"}
  },
  "required": ["type", "id"]
}
0
votes

This errors happen when validating the JSON with the schema draft-04 or higher, the problem is that "id" is expected to be in URI format and "type" as defined in the schema is an array, this names are taken, so if you want to keep the model as it is, a solution could be renaming id and type.