I am working on the webchat bot framework, more particularly on the hostconfig part of the adaptive card.
I want to use container selectaction but I do not have the expected display.
I created a basic card with container that I display on my chatbot but when I put the mouse cursor on the container, the card does not make the interactive effect yet the property supportsInteractivity is true.
Does anyone have any ideas?
Thans you
Here is my hostconfig:
{
"supportsInteractivity": true,
"spacing": {
"small": 4,
"default": 8,
"medium": 16,
"large": 24,
"extraLarge": 32,
"padding": 8
},
"separator": {
"lineThickness": 1,
"lineColor": "#cccccc"
},
"fontFamily": "\"Segoe UI\", sans-serif",
"fontSizes": {
"small": 12,
"default": 13,
"medium": 15,
"large": 17,
"extraLarge": 19
},
"fontWeights": {
"lighter": 200,
"default": 400,
"bolder": 700
},
"containerStyles": {
"default": {
"backgroundColor": "#00000000",
"foregroundColors": {
"default": {
"default": "#000000",
"subtle": "#808c95"
},
"accent": {
"default": "#2e89fc",
"subtle": "#802E8901"
},
"attention": {
"default": "#ffd800",
"subtle": "#CCFFD800"
},
"good": {
"default": "#00ff00",
"subtle": "#CC00FF00"
},
"warning": {
"default": "#ff0000",
"subtle": "#CCFF0000"
}
}
},
"emphasis": {
"backgroundColor": "#08000000",
"foregroundColors": {
"default": {
"default": "#333333",
"subtle": "#EE333333"
},
"accent": {
"default": "#2e89fc",
"subtle": "#882E89FC"
},
"attention": {
"default": "#cc3300",
"subtle": "#DDCC3300"
},
"good": {
"default": "#54a254",
"subtle": "#DD54A254"
},
"warning": {
"default": "#e69500",
"subtle": "#DDE69500"
}
}
}
},
"imageSizes": {
"small": 40,
"medium": 80,
"large": 160
},
"actions": {
"maxActions": 100,
"spacing": "default",
"buttonSpacing": 8,
"showCard": {
"actionMode": "inline",
"inlineTopMargin": 8
},
"actionsOrientation": "vertical",
"actionAlignment": "stretch"
},
"adaptiveCard": {
"allowCustomStyle": false
},
"imageSet": {
"imageSize": "medium",
"maxImageHeight": 100
},
"factSet": {
"title": {
"color": "default",
"size": "default",
"isSubtle": false,
"weight": "bolder",
"wrap": true,
"maxWidth": 150
},
"value": {
"color": "default",
"size": "default",
"isSubtle": false,
"weight": "default",
"wrap": true
},
"spacing": 8
}
}
and there is my card :
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"text": "Text",
"weight": "bolder",
"size": "large",
"color": "accent",
"horizontalAlignment": "center"
}
]
},
{
"type": "Container",
"separator": true,
"items": [
{
"type": "TextBlock",
"text": "text",
"size": "medium",
"horizontalAlignment": "center",
"wrap": true
}
]
},
{
"type": "Container",
"separator": true,
"items": [
{
"type": "TextBlock",
"text": "text",
"horizontalAlignment": "center"
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"style": "default",
"items": [
{
"type": "Container",
"style": "emphasis",
"items": [
{
"type": "TextBlock",
"text": "text"
}
],
"selectAction": {
"type": "Action.Submit",
"title": "text",
"data": {
"action": "1"
}
}
}
]
}
]
},
{
"type": "Container",
"separator": false,
"items": [
{
"type": "TextBlock",
"text": "text",
"horizontalAlignment": "center"
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"style": "default",
"items": [
{
"type": "Container",
"style": "emphasis",
"items": [
{
"type": "TextBlock",
"text": "text"
}
],
"selectAction": {
"type": "Action.Submit",
"title": "text",
"data": {
"action": "1"
}
}
}
]
}
]
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"style": "default",
"items": [
{
"type": "Container",
"style": "emphasis",
"items": [
{
"type": "TextBlock",
"text": "text"
}
],
"selectAction": {
"type": "Action.Submit",
"title": "text",
"data": {
"action": "1"
}
}
}
]
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "👍",
"data": {
"action": "2"
}
},
{
"type": "Action.ShowCard",
"title": "👎",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Text",
"id": "comment",
"isMultiline": true,
"placeholder": "Add a comment"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Soumettre",
"data": {
"action": "3"
}
}
]
}
}
]
}
Related
I am working on a Json schema for validation but it does not seem to be working.
Apart from the if then condition, the rest works fine but even though i am following the example provided in jsonschema - Applying Subschemas Conditionally, it does not work.
This is the schema
'''
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"identifierKey": {
"type": "string",
"pattern": "^[a-z][a-z0-9]*(_[a-z0-9]+)*$",
"minLength": 2
},
"uuid": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
"minLength": 36,
"maxLength": 36
},
"mail_identifierKey": {
"pattern": "^(?:(?!.*?[.]{2})[a-zA-Z0-9](?:[a-zA-Z0-9.+!%-]{1,64}|)|\"[a-zA-Z0-9.+!% -]{1,64}\")#[a-zA-Z0-9][a-zA-Z0-9.-]+(.[a-z]{2,}|.[0-9]{1,})$"
},
"question_type": {
"enum": [
"barcode",
"name",
"nps",
"single_choice",
"text",
"date",
"number",
"id",
"mail_address",
"multiple_choice",
"phone_number",
"zip_code",
"rating"
]
},
"question": {
"type": "object",
"additionalProperties": false,
"properties": {
"key": {
"$ref": "#/definitions/identifierKey"
},
"type": {
"$ref": "#/definitions/question_type"
}
},
"required": ["key", "type"]
},
"answers": {
"type":"array",
"items": {
"type": "object",
"properties": {
"question": {
"$ref": "#/definitions/question"
},
"status": {
"type": "string"
}
},
"allOf": [
{"if": {
"properties": { "question": { "const": "rating" } } },
"then": {
"properties": { "value": { "type": "number", "minimum": 1, "maximum": 5 } } }
},
{"if": {
"properties": { "question": { "const": "zip_code" } } },
"then": {
"properties": { "value": { "type": "string", "$ref": "#/definitions/identifierKey","minLength": 4, "maxLength": 10 } } }
},
{"if": {
"properties": { "question": { "const": "phone_number" } } },
"then": {
"properties": { "value": { "type": "string", "minLength": 8, "maxLength": 15 } } }
},
{"if": {
"properties": { "question": { "const": "multiple_choice" } } },
"then": {
"properties": { "value": { "type": "array", "minItems": 1, "uniqueItems": true,
"contains": { "type": "string" } }
}
}
},
{"if": {
"properties": { "question": { "const": "single_choice" } } },
"then": {
"properties": { "value": {"type": "string","$ref": "#/definitions/identifierKey"} } }
},
{"if": {
"properties": { "question": { "const": "mail_address" } } },
"then": {
"properties": { "value": {"type": "string","$ref": "#/definitions/mail_identifierKey"} } }
},
{"if": {
"properties": { "question": { "const": "id" } } },
"then": {
"properties": { "value": {"type": "string","$ref": "#/definitions/uuid"} } }
},
{"if": {
"properties": { "question": { "const": "number" } } },
"then": {
"properties": { "value": {"type": "number"} } }
},
{"if": {
"properties": { "question": { "const": "text" } } },
"then": {
"properties": { "value": {"type": "string"} } }
},
{"if": {
"properties": { "question": { "const": "date" } } },
"then": {
"properties": { "value": {"type": "string", "format": "date"} } }
},
{"if": {
"properties": { "question": { "const": "nps" } } },
"then": {
"properties": { "value": {"type": "number", "minimum": 1, "maximum":10 } } }
},
{"if": {
"properties": { "question": { "const": "name" } } },
"then": {
"properties": { "value": {"type": "string" } } }
},
{"if": {
"properties": { "question": { "const": "barcode" } } },
"then": {
"properties": { "value": {"type": "number" } } }
}
]
}
}
},
"properties": {
"answers": {
"$ref": "#/definitions/answers"
}
}
}
'''
and this is what i am trying to validate
''' {
"$schema": "./blank.json",
"answers":[ {
"status": "hello1",
"question": {
"key": "hello",
"type": "rating"
},
"value": 1234
}]
} '''
i am following the example below but not able to figure out what i am missing
https://json-schema.org/understanding-json-schema/reference/conditionals.html
Okay... I see the problem.
Here's the if subschema that you expect to trigger for your data
{
"properties": {
"question": { "const": "rating" }
}
}
However, in your data, question has a type property.
"question": {
"key": "hello",
"type": "rating"
}
This means that the if subschema isn't passing because {"key": "hello", "type": "rating" } != "rating".
You'll need to update your if subschema to account for this property hierarchy.
{
"properties": {
"question": {
"properties": {
"type": { "const": "rating" }
}
}
}
}
You'll need to do this for all of the if subschemas.
Making just this change gives this error on my validator:
{
"valid": false,
"keywordLocation": "#/properties/answers/$ref/items/allOf/0/then/properties/value/maximum",
"absoluteKeywordLocation": "https://json-everything/base#/definitions/question_type/items/allOf/0/then/properties/value/maximum",
"instanceLocation": "#/answers/0/value",
"error": "1234 is greater than or equal to 5"
}
What does the following HttpResponse-Content actually mean when using autodesk-forge's webservice to copy a file-version via the resource "data/v1/projects/{PROJECT_ID}/versions?copyFrom={ESCAPED_VERSION_ID}"?
{"jsonapi":{"version":"1.0"},
"errors":[{
"id":"3a6cb28b-6656-451c-acfb-1c68ddb24a45",
"status":"400",
"code":"ERR_BAD_INPUT",
"title":"The request has invalid header or body",
"detail":"GEN_SIZE_INVALID, details: The object size passed is too big for processing."
}]}
Is there a limit to the number of versions that can be referenced or anything like that?
Here's the payload with dummy values:
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "versions",
"relationships": {
"refs": {
"data": [
{
"type": "versions",
"id": "{{VersionURNforLink1}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink2}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink3}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink4}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink5}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink6}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink7}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink8}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink9}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink10}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink11}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink12}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink13}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink14}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink15}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink16}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink17}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink18}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink19}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink20}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink21}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink22}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink23}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
},
{
"type": "versions",
"id": "{{VersionURNforLink24}}",
"meta": {
"refType": "xrefs",
"direction": "from",
"extension": {
"type": "xrefs:autodesk.core:Xref",
"version": "1.1",
"data": {
"nestedType": "overlay"
}
}
}
}
]
}
}
}
}
From all the data we've been able to gather so far: There is in fact a limit on how many files can be referenced directly, which seems to be 50.
The reason it occurred in so many places for us when we didn't have any files referencing nearly that amount of other plans, was how the "CopyFrom"-functionality works.
Example on how to reproduce the problem:
Given "plan A" and "plan B" ("B" referencing "A"), upload both files and create their initial items/versions. Now do the following:
1.) re-upload "A" and create a new version.
2.) use "CopyFrom" on the latest version of "B" and define the reference to the latest version of "A".
Since "CopyFrom" adds references instead of replacing them, version #2 of "B" now holds two references. One towards the initial version #1 of "A" and one to the latest version of "A".
Repeat these steps enough times and you'll eventually run into this issue.
Solution:
Even though nothing except one reference has changed on "B", one needs to reupload the file defining all required references so version #N of "B" only references version #N of "A". (Be wary that this behaviour of course may change in the future!)
I have the following schema inside my Parse JSON action inside Power Automate Flow:-
{
"type": "object",
"properties": {
"_id": {
"type": "object",
"properties": {
"$oid": {
"type": "string"
}
}
},
"normalized_otherCategory": {
"type": "string"
},
"category": {
"type": "string"
},
"otherCategory": {
"type": "string"
},
"location": {
"type": "string"
},
"referenceNumber": {
"type": "string"
},
"archivingDate": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"actions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"_id": {
"type": "object",
"properties": {
"$oid": {
"type": "string"
}
}
},
"type": {
"type": "string"
},
"user": {
"type": "string"
},
"timestamp": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"normalized_comment": {
"type": "array"
},
"configs": {
"type": "array"
},
"comment": {
"type": "string"
}
},
"required": [
"_id",
"type",
"user",
"timestamp",
"normalized_comment",
"configs"
]
}
},
"otherAttributes": {
"type": "array"
},
"attributes": {
"type": "array"
},
"timestamp": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"foundDate": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"trainFoundAt": {
"type": "object",
"properties": {
"number": {
"type": "string"
},
"car": {
"type": "string"
},
"seat": {
"type": "string"
}
}
},
"status": {
"type": "string"
},
"matchIdNumber": {
"type": "string"
},
"__v": {
"type": "integer"
},
"imageData": {
"type": "object",
"properties": {
"originalName": {
"type": "string"
},
"contentType": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"$binary": {
"type": "string"
},
"$type": {
"type": "string"
}
}
}
}
},
"imageThumbData": {
"type": "object",
"properties": {
"originalName": {
"type": "string"
},
"contentType": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"$binary": {
"type": "string"
},
"$type": {
"type": "string"
}
}
}
}
},
"stationFoundAt": {
"type": "string"
}
},
"required": [
"_id",
"normalized_otherCategory",
"category",
"location",
"referenceNumber",
"archivingDate",
"actions",
"otherAttributes",
"attributes",
"timestamp",
"foundDate",
"status",
"matchIdNumber",
"__v"
]
}
but it is raising this error on 5% of the items, while working well for the other 95% items:-
{
"errors": [
{
"message": "Invalid type. Expected String but got Null.",
"lineNumber": 0,
"linePosition": 0,
"path": "stationFoundAt",
"schemaId": "#/properties/stationFoundAt",
"errorType": "type",
"childErrors": []
}
]
}
here is a sample of one of the inputs which is raising this error:-
{
"content": {
"_id": {
"$oid": "5daa037cb66a2c601510e8aa"
},
"normalized_otherCategory": "purse,type,wallet",
"category": "other",
"otherCategory": "Purse-Type Wallet",
"location": "ontrain",
"referenceNumber": "VIAF-000009475",
"archivingDate": {
"$date": "2019-11-15T00:00:00.000Z"
},
"actions": [
{
"user": "PA454196",
"type": "created",
"_id": {
"$oid": "5daa037cb66a2c601510e8a9"
},
"timestamp": {
"$date": "2019-10-18T18:25:00.426Z"
},
"normalized_comment": [],
"configs": []
},
{
"_id": {
"$oid": "5daa037cb66a2c601510e8a8"
},
"user": "PA454196",
"comment": "",
"type": "comment",
"timestamp": {
"$date": "2019-10-18T18:25:00.425Z"
},
"normalized_comment": [],
"configs": []
},
{
"_id": {
"$oid": "5daa037cb66a2c601510e8a7"
},
"user": "PA454196",
"type": "stored",
"timestamp": {
"$date": "2019-10-18T18:25:00.425Z"
},
"normalized_comment": [],
"configs": [
"container-1",
"station-toronto"
]
},
{
"_id": {
"$oid": "5daa03b9b66a2c601510e8ab"
},
"user": "PA454196",
"type": "comment",
"comment": "black nylon",
"timestamp": {
"$date": "2019-10-18T00:00:00.000Z"
},
"normalized_comment": [
"black",
"nylon"
],
"configs": []
},
{
"_id": {
"$oid": "5db1d7481fccee641499efd1"
},
"user": "GR452944",
"type": "comment",
"comment": "pax lives in Australia. currently awaiting for Address and authorization to send to Australia from Management ",
"timestamp": {
"$date": "2019-10-24T00:00:00.000Z"
},
"normalized_comment": [
"pax",
"lives",
"in",
"australia",
"currently",
"awaiting",
"for",
"address",
"and",
"authorization",
"to",
"send",
"to",
"australia",
"from",
"management"
],
"configs": []
},
{
"comment": "Bryan Lim\n12/3 Rockley Road\nSouth Yarra\nVictoria \nAUSTRALIA 3141\n",
"type": "comment",
"user": "GR452944",
"_id": {
"$oid": "5db9d0d53da9956709808899"
},
"timestamp": {
"$date": "2019-10-30T00:00:00.000Z"
},
"normalized_comment": [
"bryan",
"lim",
"123",
"rockley",
"road",
"south",
"yarra",
"victoria",
"australia",
"3141"
],
"configs": []
},
{
"comment": "OCT 30- Sent by Canada Post, tracking number LX035418234CA",
"type": "comment",
"user": "CH454138",
"_id": {
"$oid": "5db9d73d8e450c67172d0dea"
},
"timestamp": {
"$date": "2019-10-30T00:00:00.000Z"
},
"normalized_comment": [
"oct",
"30",
"sent",
"by",
"canada",
"post",
"tracking",
"number",
"lx035418234ca"
],
"configs": []
}
],
"otherAttributes": [],
"attributes": [],
"timestamp": {
"$date": "2019-10-18T18:25:00.423Z"
},
"foundDate": {
"$date": "2019-10-16T00:00:00.000Z"
},
"trainFoundAt": {
"number": "55",
"car": "3323",
"seat": ""
},
"status": "opened",
"pnrNumber": "VWZ975",
"matchIdNumber": "",
"__v": 4,
"imageData": {
"originalName": "20191018_142530[1].jpg_big.jpg",
"contentType": "images/jpeg",
"data": {
"$binary": "/9j/*****5qTxPbNfy2t/dMp3oEVd2Oe4FUb/w9O0dvd3xd4VTYis+Qgz0zWW/ZUTalof02pLM266i8pVR2G4gCuo9o9vJB4fuEjV1LhjGhPKrj3rql0Ks/9k=",
"$type": "00"
}
},
"imageThumbData": {
"originalName": "20191018_142530[1].jpg_thumb.jpg",
"contentType": "images/jpeg",
"data": {
"$binary": "/9j/***SP/2Q==",
"$type": "00"
}
},
"stationFoundAt": null
},
"schema": {
"type": "object",
"properties": {
"_id": {
"type": "object",
"properties": {
"$oid": {
"type": "string"
}
}
},
"normalized_otherCategory": {
"type": "string"
},
"category": {
"type": "string"
},
"otherCategory": {
"type": "string"
},
"location": {
"type": "string"
},
"referenceNumber": {
"type": "string"
},
"archivingDate": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"actions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"_id": {
"type": "object",
"properties": {
"$oid": {
"type": "string"
}
}
},
"type": {
"type": "string"
},
"user": {
"type": "string"
},
"timestamp": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"normalized_comment": {
"type": "array"
},
"configs": {
"type": "array"
},
"comment": {
"type": "string"
}
},
"required": [
"_id",
"type",
"user",
"timestamp",
"normalized_comment",
"configs"
]
}
},
"otherAttributes": {
"type": "array"
},
"attributes": {
"type": "array"
},
"timestamp": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"foundDate": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"trainFoundAt": {
"type": "object",
"properties": {
"number": {
"type": "string"
},
"car": {
"type": "string"
},
"seat": {
"type": "string"
}
}
},
"status": {
"type": "string"
},
"matchIdNumber": {
"type": "string"
},
"__v": {
"type": "integer"
},
"imageData": {
"type": "object",
"properties": {
"originalName": {
"type": "string"
},
"contentType": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"$binary": {
"type": "string"
},
"$type": {
"type": "string"
}
}
}
}
},
"imageThumbData": {
"type": "object",
"properties": {
"originalName": {
"type": "string"
},
"contentType": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"$binary": {
"type": "string"
},
"$type": {
"type": "string"
}
}
}
}
},
"stationFoundAt": {
"type": "string"
}
},
"required": [
"_id",
"normalized_otherCategory",
"category",
"location",
"referenceNumber",
"archivingDate",
"actions",
"otherAttributes",
"attributes",
"timestamp",
"foundDate",
"status",
"matchIdNumber",
"__v"
]
}
}
here is a JSON which was parsed successfully:-
{
"content": {
"_id": {
"$oid": "5dde57bffeaf3f770907b144"
},
"normalized_otherCategory": "books,of,numbers",
"category": "books",
"otherCategory": "books of numbers",
"location": "ontrain",
"referenceNumber": "VIAF-000010334",
"archivingDate": {
"$date": "2020-02-24T00:00:00.000Z"
},
"actions": [
{
"_id": {
"$oid": "5dde57bffeaf3f770907b143"
},
"type": "created",
"user": "SO202505",
"timestamp": {
"$date": "2019-11-27T11:02:23.899Z"
},
"normalized_comment": [],
"configs": []
},
{
"type": "comment",
"comment": "",
"user": "SO202505",
"_id": {
"$oid": "5dde57bffeaf3f770907b142"
},
"timestamp": {
"$date": "2019-11-27T11:02:23.899Z"
},
"normalized_comment": [],
"configs": []
},
{
"type": "stored",
"user": "SO202505",
"_id": {
"$oid": "5dde57bffeaf3f770907b141"
},
"timestamp": {
"$date": "2019-11-27T11:02:23.899Z"
},
"normalized_comment": [],
"configs": [
"container-2",
"station-quebec"
]
}
],
"otherAttributes": [],
"attributes": [],
"timestamp": {
"$date": "2019-11-27T11:02:23.898Z"
},
"foundDate": {
"$date": "2019-11-26T00:00:00.000Z"
},
"trainFoundAt": {
"number": "28",
"car": "3",
"seat": "12c"
},
"status": "opened",
"pnrNumber": "",
"matchIdNumber": "",
"__v": 0,
"imageData": {
"originalName": "WIN_20191127_05_55_39_Pro.jpg_big.jpg",
"contentType": "images/jpeg",
"data": {
"$binary": "/9j/2****oI2SuUUUI/sRZ//9k=",
"$type": "00"
}
},
"imageThumbData": {
"originalName": "WIN_20191127_05_55_39_Pro.jpg_thumb.jpg",
"contentType": "images/jpeg",
"data": {
"$binary": "/9j/****Bn//2Q==",
"$type": "00"
}
}
},
"schema": {
"type": "object",
"properties": {
"_id": {
"type": "object",
"properties": {
"$oid": {
"type": "string"
}
}
},
"normalized_otherCategory": {
"type": "string"
},
"category": {
"type": "string"
},
"otherCategory": {
"type": "string"
},
"location": {
"type": "string"
},
"referenceNumber": {
"type": "string"
},
"archivingDate": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"actions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"_id": {
"type": "object",
"properties": {
"$oid": {
"type": "string"
}
}
},
"type": {
"type": "string"
},
"user": {
"type": "string"
},
"timestamp": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"normalized_comment": {
"type": "array"
},
"configs": {
"type": "array"
},
"comment": {
"type": "string"
}
},
"required": [
"_id",
"type",
"user",
"timestamp",
"normalized_comment",
"configs"
]
}
},
"otherAttributes": {
"type": "array"
},
"attributes": {
"type": "array"
},
"timestamp": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"foundDate": {
"type": "object",
"properties": {
"$date": {
"type": "string"
}
}
},
"trainFoundAt": {
"type": "object",
"properties": {
"number": {
"type": "string"
},
"car": {
"type": "string"
},
"seat": {
"type": "string"
}
}
},
"status": {
"type": "string"
},
"matchIdNumber": {
"type": "string"
},
"__v": {
"type": "integer"
},
"imageData": {
"type": "object",
"properties": {
"originalName": {
"type": "string"
},
"contentType": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"$binary": {
"type": "string"
},
"$type": {
"type": "string"
}
}
}
}
},
"imageThumbData": {
"type": "object",
"properties": {
"originalName": {
"type": "string"
},
"contentType": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"$binary": {
"type": "string"
},
"$type": {
"type": "string"
}
}
}
}
},
"stationFoundAt": {
"type": "string"
}
},
"required": [
"_id",
"normalized_otherCategory",
"category",
"location",
"referenceNumber",
"archivingDate",
"actions",
"otherAttributes",
"attributes",
"timestamp",
"foundDate",
"status",
"matchIdNumber",
"__v"
]
}
}
can anyone advice how i can fix this error for the 5% of the items?
Thanks
For string properties that can be null the type declaration should be defined as { "type": ["string", "null"] }.
Here is my JSON schema and JSON as shown below at the bottom and using ajv validator to support json spec draft 7.
By default, the 'science' object must be represented as:
//Default science object
{"type": "science", "rule": {"sciencePattern": {}}}
where the 'rule' and 'sciencePattern' MUST be there.
However, if the 'sciencePattern' about to contains other attributes (as per the schema), then the below validation should kick in:
If the default science object is present, then the "scored" attributes in "arts" object should be REQUIRED.
If the NESTED "scored" array attribute is present within rule as:
{ "type": "science", "rule":{"sciencePattern":{"marks":{"scored":[10]}}} }
then the "scored" attributes in "arts" object should not be REQUIRED. In other words, if some one specify "scored" attribute withn the "arts" object, the schema validation should complain as there is a "scored" attribute is available in "science" object.
//JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"exam"
],
"properties": {
"exam": {
"type": "array",
"minItems": 1,
"items": {
"anyOf": [
{
"$ref": "#/definitions/science"
},
{
"$ref": "#/definitions/arts"
}
]
}
},
"if": {
"type": "object",
"required": [
"type",
"rule"
],
"properties": {
"type": {
"const": "science"
},
"rule": {
"type": "object",
"required": [
"sciencePattern"
],
"properties": {
"sciencePattern": {
"$ref": "#/definitions/sciencePattern"
}
}
}
}
},
"then": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"const": "arts"
},
"not": {
"required": [
"scored"
]
}
}
}
},
"definitions": {
"sciencePattern": {
"type": "object",
"required": [
"marks"
],
"properties": {
"marks": {
"type": "object",
"required": [
"scored"
],
"properties": {
"scored": {
"type": "array"
}
}
}
}
},
"science": {
"type": "object",
"properties": {
"type": {
"const": "science"
},
"rule": {
"required": [
"sciencePattern"
],
"properties": {
"sciencePattern": {
"$ref": "#/definitions/sciencePattern"
}
}
}
}
},
"arts": {
"required": [
"scored"
],
"properties": {
"type": {
"const": "arts"
},
"scored": {
"type": "number"
},
"remarks": {
"type": "string"
}
}
}
}
}
and My JSON
{
"exam": [
{
"type": "science",
"rule": {
"sciencePattern": {
"marks": {
"scored": [10]
}
}
}
},
{
"type": "arts",
"scored": 10 //This should complain as 'scored' is available above in science
}
]
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"exam"
],
"properties": {
"exam": {
"type": "array",
"allOf":[
{
"if": {
"contains": {
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"const": "science"
}
}
}
},
"then":{
"required":["rule", "sciencePattern"]
}
},
{
"if": {
"contains": {
"type": "object",
"required":["type","rule", "sciencePattern"],
"properties": {
"type": {
"const": "science"
}
}
}
},
"then":{
"required":["scored"]
}
},
{
"if": {
"contains": {
"type": "object",
"required": [
"type",
"rule"
],
"properties": {
"type": {
"const": "science"
},
"rule": {
"type": "object",
"required": [
"sciencePattern"
],
"properties": {
"sciencePattern": {
"$ref": "#/definitions/emptySciencePattern"
}
}
}
}
}
},
"then": {
"contains": {
"type": "object",
"required": ["type", "scored"],
"properties": {
"type": {
"const": "arts"
}
}
}
},
"else": {
"if": {
"contains": {
"type": "object",
"required": [
"type",
"rule"
],
"properties": {
"type": {
"const": "science"
},
"rule": {
"type": "object",
"required": [
"sciencePattern"
],
"properties": {
"sciencePattern": {
"$ref": "#/definitions/sciencePattern"
}
}
}
}
}
},
"then": {
"contains": {
"required": [
"type"
],
"properties": {
"type": {
"const": "arts"
}
},
"not": {
"required": ["scored"]
}
}
}
}
}],
"minItems": 1,
"items": {
"anyOf": [{
"$ref": "#/definitions/science"
}, {
"$ref": "#/definitions/arts"
}]
}
}
},
"definitions": {
"rule": {
"type": "object",
"required": ["sciencePattern"],
"properties": {
"sciencePattern": {
"$ref": "#/definitions/sciencePattern"
}
}
},
"emptySciencePattern": {
"type": "object",
"maxProperties": 0,
"additionalProperties": false,
"properties": {}
},
"sciencePattern": {
"type": "object",
"properties": {
"marks": {
"type": "object",
"properties": {
"scored": {
"type": "array"
}
}
}
}
},
"science": {
"type": "object",
"required": ["rule"],
"properties": {
"type": {
"const": "science"
},
"rule": {
"$ref":"#/definitions/rule"
}
}
},
"arts": {
"properties": {
"type": {
"const": "arts"
},
"scored": {
"type": "number"
},
"remarks": {
"type": "string"
}
}
}
}
}
Here is the criteria: the individual region object can co-exist withing the array along with ONLY asia/europe/austrlia (either one region at a time from asia/europe/austrlia).
In addition to this every region object can have few required attributes and nested one.
The issue is the schema validator is not complaining about the required attribute (i.e. width attribute from dimension object)
Here is the JSON Schema
{
"type": "object",
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"stat_data": {
"type": "array",
"if": {
"contains": {
"type": "object",
"properties": {
"region": {
"type": "string",
"enum": [
"europe"
]
}
}
}
},
"then": {
"not": {
"contains": {
"type": "object",
"properties": {
"region": {
"type": "string",
"enum": [
"asia",
"australia"
]
}
}
}
}
},
"else": {
"if": {
"contains": {
"type": "object",
"properties": {
"region": {
"type": "string",
"enum": [
"asia"
]
}
}
}
},
"then": {
"not": {
"contains": {
"type": "object",
"properties": {
"region": {
"type": "string",
"enum": [
"europe",
"australia"
]
}
}
}
}
},
"else": {
"if": {
"contains": {
"type": "object",
"properties": {
"region": {
"type": "string",
"enum": [
"australia"
]
}
}
}
},
"then": {
"not": {
"contains": {
"type": "object",
"properties": {
"region": {
"type": "string",
"enum": [
"europe",
"asia"
]
}
}
}
}
},
"else": {}
}
},
"items": {
"type": "object",
"properties": {
"details": {
"$ref": "#/definitions/dimension"
},
"population": {
"$ref": "#/definitions/details"
},
"dimension": {
"$ref": "#/definitions/population"
},
"region": {
"enum": [
"asia",
"europe",
"australia",
"some-pencil-region",
"some-oil-pastels-region"
]
}
}
}
}
},
"definitions": {
"dimension": {
"type": "object",
"required": [
"width"
],
"properties": {
"height": {
"type": "integer"
},
"width": {
"type": "integer"
}
}
},
"details": {
"type": "object",
"properties": {
"brand": {
"type": "string"
},
"year": {
"type": "integer"
}
}
},
"population": {
"type": "object",
"properties": {
"change": {
"type": "integer"
},
"year": {
"type": "integer"
}
}
}
}
}
and the JSON
{
"stat_data": [
{
"region": "some-pencil-region",
"details": {
"brand": "Camlin",
"year": 2019
}
},
{
"region": "some-oil-pastels-region",
"height": 30
},
{
"region": "asia",
"population": {
"year": 2018,
"change": 2
}
}
]
}
You can check at _https://jsonschema.dev/ by copying schema and json in the editor
Maybe your JSON validator doesn't catch the issue? JSONBuddy shows a message about a missing "width" property: