Convert Nested Json Schem to Pyspark Schema - json

I have a schema which has nested fields.When I try to convert it with:
jtopy=json.dumps(schema_message['SchemaDefinition']) #json.dumps take a dictionary as input and returns a string as output.
print(jtopy)
dict_json=json.loads(jtopy) # json.loads take a string as input and returns a dictionary as output.
print(dict_json)
new_schema = StructType.fromJson(dict_json)
print(new_schema)
It returns error:
return StructType([StructField.fromJson(f) for f in json["fields"]])
TypeError: string indices must be integers
The schema is Definition as described below is what Im passing
{
"type": "record",
"name": "tags",
"namespace": "com.tigertext.data.events.tags",
"doc": "Schema for tags association to accounts (role,etc..)",
"fields": [
{
"name": "header",
"type": {
"type": "record",
"name": "eventHeader",
"namespace": "com.tigertext.data.events",
"doc": "Metadata about the event record.",
"fields": [
{
"name": "topic",
"type": "string",
"doc": "The topic this record belongs to. e.g. messages"
},
{
"name": "server",
"type": "string",
"doc": "The server that generated this event. e.g. xmpp-07"
},
{
"name": "service",
"type": "string",
"doc": "The service that generated this event. e.g. erlang-producer"
},
{
"name": "environment",
"type": "string",
"doc": "The environment this record belongs to. e.g. dev, prod"
},
{
"name": "time",
"type": "long",
"doc": "The time in epoch this record was produced."
}
]
}
},
{
"name": "eventType",
"type": {
"type": "enum",
"name": "eventType",
"symbols": [
"CREATE",
"UPDATE",
"DELETE",
"INIT"
]
},
"doc": "event type"
},
{
"name": "tagId",
"type": "string",
"doc": "Tag ID for the tag"
},
{
"name": "orgToken",
"type": "string",
"doc": "org ID"
},
{
"name": "tagName",
"type": "string",
"doc": "name of the tag"
},
{
"name": "colorId",
"type": "string",
"doc": "color id"
},
{
"name": "colorName",
"type": "string",
"doc": "color name"
},
{
"name": "colorValue",
"type": "string",
"doc": "color value e.g. #C8C8C8"
},
{
"name": "entities",
"type": [
"null",
{
"type": "array",
"items": {
"type": "record",
"name": "entity",
"fields": [
{
"name": "entityToken",
"type": "string"
},
{
"name": "entityType",
"type": "string"
}
]
}
}
],
"default": null
}
]
}
Above is the schema of the kafka topic I want to parse into pyspark schema

Related

Unable to create sample data for avro schema Error creating a kafka message to producer - Expected start-union. Got VALUE_STRING

Unable to Error creating a kafka message to producer - Expected start-union. Got VALUE_STRING
{
"namespace": "de.morris.audit",
"type": "record",
"name": "AuditDataChangemorris",
"fields": [
{"name": "employeeID", "type": "string"},
{"name": "employeeNumber", "type": ["null", "string"], "default": null},
{"name": "serialNumbers", "type": [ "null", {"type": "array", "items": "string"}]},
{"name": "correlationId", "type": "string"},
{"name": "timestamp", "type": "long", "logicalType": "timestamp-millis"},
{"name": "employmentscreening","type":{"type": "enum", "name": "employmentscreening", "symbols": ["NO","YES"]}},
{"name": "vouchercodes","type": ["null",
{
"type": "array",
"items": {
"name": "Vouchercodes",
"type": "record",
"fields": [
{"name": "voucherName","type": ["null","string"], "default": null},
{"name": "authocode","type": ["null","string"], "default": null}
]
}
}], "default": null}
]
}
when i was trying to create a sample data in json format based on the above avsc for kafka consumer i am getting the below error upon testing
{
"employeeID": "qtete46524",
"employeeNumber": {
"string": "custnumber9813"
},
"serialNumbers": {
"type": "array",
"items": ["363536623","5846373733"]
},
"correlationId": "corr-656532443",
"timestamp": 1476538955719,
"employmentscreening": "NO",
"vouchercodes": [
{
"voucherName": "skygo",
"authocode": "A238472ASD"
}
]
}
getting the below error when i got when i ran the dataflow job in gcp
Error message from worker: java.lang.RuntimeException: java.io.IOException: Insert failed: [{"errors":[{"debugInfo":"","location":"serialnumbers","message":"Array specified for non-repeated field: serialnumbers.","reason":"invalid"}],"index":0}]**
how to create correct sample data based on the above schema ?
Read the spec
The value of a union is encoded in JSON as follows:
if its type is null, then it is encoded as a JSON null;
otherwise it is encoded as a JSON object with one name/value pair whose name is the type’s name and whose value is the recursively encoded value
So, here's the data it expects.
{
"employeeID": "qtete46524",
"employeeNumber": {
"string": "custnumber9813"
},
"serialNumbers": {"array": [
"serialNumbers3521"
]},
"correlationId": "corr-656532443",
"timestamp": 1476538955719,
"employmentscreening": "NO",
"vouchercodes": {"array": [
{
"voucherName": {"string": "skygo"},
"authocode": {"string": "A238472ASD"}
}
]}
}
With this schema
{
"namespace": "de.morris.audit",
"type": "record",
"name": "AuditDataChangemorris",
"fields": [
{
"name": "employeeID",
"type": "string"
},
{
"name": "employeeNumber",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "serialNumbers",
"type": [
"null",
{
"type": "array",
"items": "string"
}
]
},
{
"name": "correlationId",
"type": "string"
},
{
"name": "timestamp",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "employmentscreening",
"type": {
"type": "enum",
"name": "employmentscreening",
"symbols": [
"NO",
"YES"
]
}
},
{
"name": "vouchercodes",
"type": [
"null",
{
"type": "array",
"items": {
"name": "Vouchercodes",
"type": "record",
"fields": [
{
"name": "voucherName",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "authocode",
"type": [
"null",
"string"
],
"default": null
}
]
}
}
],
"default": null
}
]
}
Here's an example of producing and consuming to Kafka
$ jq -rc < /tmp/data.json | kafka-avro-console-producer --topic foobar --property value.schema="$(jq -rc < /tmp/data.avsc)" --bootstrap-server localhost:9092 --sync
$ kafka-avro-console-consumer --topic foobar --from-beginning --bootstrap-server localhost:9092 | jq
{
"employeeID": "qtete46524",
"employeeNumber": {
"string": "custnumber9813"
},
"serialNumbers": {
"array": [
"serialNumbers3521"
]
},
"correlationId": "corr-656532443",
"timestamp": 1476538955719,
"employmentscreening": "NO",
"vouchercodes": {
"array": [
{
"voucherName": {
"string": "skygo"
},
"authocode": {
"string": "A238472ASD"
}
}
]
}
}
^CProcessed a total of 1 messages

How to parse a dynamic Json - Power Automate

Im getting a http response from Azure LogAnalytics, the response is a Json like this
{
"tables": [
{
"name": "PrimaryResult",
"columns": [
{
"name": "TimeGenerated",
"type": "datetime"
},
{
"name": "DestinationIP",
"type": "string"
},
{
"name": "DestinationUserName",
"type": "string"
},
{
"name": "country_name",
"type": "string"
},
{
"name": "country_iso_code",
"type": "string"
},
{
"name": "AccountCustomEntity",
"type": "string"
}
],
"rows": [
[
"2021-05-17T14:07:01.878Z",
"158.000.000.33",
"luis",
"United States",
"US",
"luis"
]
]
}
]
}
I will never get the same colums or sometimes i will get more rows with data like this
{
"tables": [
{
"name": "PrimaryResult",
"columns": [
{
"name": "Account",
"type": "string"
},
{
"name": "Computer",
"type": "string"
},
{
"name": "IpAddress",
"type": "string"
},
{
"name": "AccountType",
"type": "string"
},
{
"name": "Activity",
"type": "string"
},
{
"name": "LogonTypeName",
"type": "string"
},
{
"name": "ProcessName",
"type": "string"
},
{
"name": "StartTimeUtc",
"type": "datetime"
},
{
"name": "EndTimeUtc",
"type": "datetime"
},
{
"name": "ConnectinCount",
"type": "long"
},
{
"name": "timestamp",
"type": "datetime"
},
{
"name": "AccountCustomEntity",
"type": "string"
},
{
"name": "HostCustomEntity",
"type": "string"
},
{
"name": "IPCustomEntity",
"type": "string"
}
],
"rows": [
[
"abc\\abc",
"EQ-DC02.abc.LOCAL",
"0.0.0.0",
"User",
"4624 - An account was successfully logged on.",
"10 - RemoteInteractive",
"C:\\Windows\\System32\\svchost.exe",
"2021-05-17T15:02:25.457Z",
"2021-05-17T15:02:25.457Z",
2,
"2021-05-17T15:02:25.457Z",
"abc\\abc",
"EQ-DC02.abc.LOCAL",
"0.0.0.0"
],
[
"abc\\eona",
"EQPD-SW01.abc.LOCAL",
"0.0.0.0",
"User",
"4624 - An account was successfully logged on.",
"10 - RemoteInteractive",
"C:\\Windows\\System32\\svchost.exe",
"2021-05-17T15:21:45.993Z",
"2021-05-17T15:21:45.993Z",
1,
"2021-05-17T15:21:45.993Z",
"abc\\abc",
"EQPD-SW01.abc.LOCAL",
"0.0.0.0"
]
]
}
]
}
Im using Power Automate to parse this kind of Json to a Object or to make a response
the question is, how can i parse this "Columns" and "Rows" to a object?
Similar discussion happened in community forum and the solution identified was:
parse JSON and transform it to XML and then search keys with XPATH in Flow

Swagger JSON - How could I fix a response render error?

I have been trying to fix an error where the Swagger would not render my JSON response - here is an attached picture of it.
The console does not show any errors so I am struggling to allocate from where the issue could be coming - here is the console result.
I would be extremely thankful if someone could suggest a way to fix that problem.
Here is my code:
"paths": {
"/unit/{jobs}": {
"get": {
"tags": [
"Services"
],
"summary": "Jobs information",
"description": "Returns JSON with content of jobs details.",
"operationId": "unitJobs",
"security": [
{
"Application": []
},
{
"Profile": []
},
{
"Authorization": []
}
],
"parameters": [
{
"name": "jobs",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Jobs"
}
],
"responses": {
"200": {
"description": "Success!",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Job"
}
}
}
}
}
}
}
},
"components": {
"securitySchemes": {
"Application": {
"name": "X-Application",
"type": "apiKey",
"in": "header"
},
"Profile": {
"name": "X-Profile",
"type": "apiKey",
"in": "header"
},
"Authorization": {
"type": "http",
"scheme": "bearer"
}
},
"schemas": {
"Job": {
"properties": {
"id": {
"type": "integer",
"example": 2584075,
"description": "Unique identifier"
},
"currency_code": {
"type": "string",
"example": "GBP",
"description": "Currency code"
},
"payment_method": {
"type": "array"
},
"app_time": {
"type": "integer",
"example": 1504620000,
"description": "Appointment time for the job in UTC timestamp"
},
"flexible_from": {
"type": "integer",
"example": null,
"description": "Start of timeframe to execute the job in UTC timestamp"
},
"flexible_to": {
"type": "integer",
"example": null,
"description": "End of timeframe to execute the job in UTC timestamp"
},
"insufficient_travel_time_warning_time": {
"type": "integer",
"example": "1504616400",
"description": "Time up until Pro should leave previous job in order to get to this job in time in UTC timestamp"
},
"total_formatted": {
"type": "string",
"example": "£97",
"description": "Price of the service after discounts"
},
"base_total_formatted": {
"type": "string",
"example": "£97",
"description": "Price of the service before discounts"
},
"price_notes": {
"type": "array",
"example": [
"Credit applied",
"Compensation included"
],
"description": "Description notes for the price of the services."
},
"require_summary": {
"type": "integer",
"example": 4,
"description": "\n * `0` - No summary required \n * `1` - Should send summary at the end of the day \n * `2` - Should send summary now \n * `3` - Can’t proceed until summary sent \n * `4` - Summary sent"
},
"work_time": {
"type": "integer",
"example": 120,
"description": "Job duration in minutes"
},
"valid_to": {
"type": "integer",
"example": "1504620000",
"description": "Time after which job is no more valid and has to be updated in UTC timestamp"
},
"attachments.origin_key": {
"type": "string",
"example": "checklist",
"description": "\n Identifies where the attachment is coming from: \n * `checklist` - from answering a question that requires attachment \n * `job` - from job screen \n * `configurator` - from booking process when filling a choice item of type attachment"
},
"services_price_modifiers": {
"type": "array",
"example": ""
},
"reference_number": {
"type": "string",
"example": "20082602SYS",
"description": "Unique identifying number for each job"
},
"purchase_order_number": {
"type": "string",
"example": "12-13-14-15-16",
"description": "Unique number assigned to a purchase order form"
},
"contacts": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Contact"
}
},
"message_templates": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MessageTemplate"
}
},
"decline_reason_groups": {
"type": "array",
"items": {
"$ref": "#/components/schemas/DeclineReasonGroup"
}
},
"icons": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Icon"
}
}
}
},
"Contact": {
"properties": {
"id": {
"type": "integer",
"example": 203,
"description": "Unique identifier"
},
"value": {
"type": "string",
"example": "02034042956",
"description": "Contact number"
},
"type": {
"$ref": "#/components/schemas/ContactType"
},
"description": {
"type": "string",
"example": "Customer Service",
"description": "Name of the corresponding department"
},
"display_positions": {
"type": "array",
"example": [
2,
3,
7
],
"description": ""
}
}
},
"MessageTemplate": {
"properties": {
"id": {
"type": "integer",
"example": 15,
"description": "Unique identifier"
},
"title": {
"type": "string",
"example": "In front of the property",
"description": "Template message title"
},
"message": {
"type": "string",
"example": "Dear [CLIENT_NAME], I am in front of your property. Please let me in or call our office on 02034041930. Your Fantastic Professional",
"description": "The containing text of the message"
},
"vars": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Var"
},
},
"destination_option_title": {
"type": "string",
"example": "to office",
"description": "Optionally defines the destination of the title"
}
}
},
"DeclineReasonGroup": {
"properties": {
"title": {
"type": "string",
"example": "Technical issues",
"description": "Decline reason title"
},
"sort": {
"type": "integer",
"example": 100,
"description": ""
},
"decline_reasons": {
"type": "array",
"items": {
"$ref": "#/components/schemas/DeclineReason"
}
}
}
},
"Icon": {
"properties": {
"name": {
"type": "string",
"example": "Key:",
"description": "The name of the icon"
},
"note": {
"type": "string",
"example": "Yes",
"description": "Addiditonal information about the icon"
}
}
},
"Var": {
"properties": {
"variable": {
"type": "string",
"example": "CLIENT_NAME",
"description": "Different client details"
},
"type": {
"$ref": "#/components/schemas/VarType"
},
"field": {
"type": "string",
"example": "clientName",
"description": "Fields where the client's information is filled"
}
}
},
"DeclineReason": {
"properties": {
"id": {
"type": "integer",
"example": 11,
"description": "Unique identifier"
},
"name": {
"type": "string",
"example": "Car is broken",
"description": "The name of a decline reason"
},
"requires_comment": {
"type": "boolean",
"example": true,
"description": "Determines whether the comment section is required to be filled "
},
"success_message": {
"type": "string",
"example": "Please contact Stanimir Tomov on 07472761402 - he can find you another.",
"description": "The message which pops up after the request made is successful"
},
"sort": {
"type": "integer",
"example": 100,
"description": ""
}
}
},
"ContactType": {
"type": "integer",
"enum": [
1,
2,
3,
4
],
"description": "* `1` - Customer Service \n * `2` - Sales \n * `3` - Finance \n * `4` - Other"
},
"VarType": {
"type": "string",
"enum": [
"auto",
"manual"
],
"description": "* `auto` - information being filled automatically \n * `manual` - information being filled manually "
}
}
}
}
The problem is not the responses them selves, rather it is the definition of the 'payment_method' in the Job schema:
You need to define the items in an array definition, try this:
"payment_method": {
"type": "array",
"items": {
"type": "string"
}
}

Importing a nested json as a table with multiple nesting

In our data we have json fields that include repeated sections, as well as infinite nesting possibilities (the samples I have so far are quite simplistic). After seeing BQ repeated fields and records, I decided to try restructuring the data into repeated record fields, as our use case is related to analytics and then wanted to test out different use cases for the data to see which approach is more efficient (time/cost/difficulty) for the analysis we intend to do on it. I have created a sample json record that I want to upload to BQ, that uses all the features that I think we would need (I have validated is using http://jsonlint.com/):
{
"aid": "6dQcrgMVS0",
"hour": "2016042723",
"unixTimestamp": "1461814784",
"browserId": "BdHOHp2aL9REz9dXVeKDaxdvefE3Bgn6NHZcDQKeuC67vuQ7PBIXXJda3SOu",
"experienceId": "EXJYULQOXQ05",
"experienceVersion": "1.0",
"pageRule": "V1XJW61TPI99UWR",
"userSegmentRule": "67S3YVMB7EMQ6LP",
"branch": [{
"branchId": "1",
"branchType": "userSegments",
"itemId": "userSegment67S3YVMB7EMQ6LP",
"headerId": "null",
"itemMethod": "null"
}, {
"branchId": "1",
"branchType": "userSegments",
"itemId": "userSegment67S3YVMB7EMQ6LP",
"headerId": "null",
"itemMethod": "null"
}],
"event": [{
"eventId": "546",
"eventName": "testEvent",
"eventDetails": [{
"key": "a",
"value": "1"
}, {
"key": "b",
"value": "2"
}, {
"key": "c",
"value": "3"
}]
}, {
"eventId": "547",
"eventName": "testEvent2",
"eventDetails": [{
"key": "d",
"value": "4"
}, {
"key": "e",
"value": "5"
}, {
"key": "f",
"value": "6"
}]
}]
}
I am using BQ interface, to upload this json into a table with the following structure:
[
{
"name": "aid",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "hour",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "unixTimestamp",
"type": "INTEGER",
"mode": "NULLABLE"
},
{
"name": "browserId",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "experienceId",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "experienceVersion",
"type": "FLOAT",
"mode": "NULLABLE"
},
{
"name": "pageRule",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "userSegmentRule",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "branch",
"type": "RECORD",
"mode": "REPEATED",
"fields": [
{
"name": "branchId",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "branchType",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "itemId",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "headerId",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "itemMethod",
"type": "STRING",
"mode": "NULLABLE"
}
]
},
{
"name": "event",
"type": "RECORD",
"mode": "REPEATED",
"fields": [
{
"name": "evenId",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "eventName",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "eventDetails",
"type": "RECORD",
"mode": "REPEATED",
"fields": [
{
"name": "key",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "value",
"type": "STRING",
"mode": "NULLABLE"
}
]
}
]
}
]
My jobs fail with a
JSON parsing error in row starting at position 0 in <file_id>. Expected key (error code: invalid)
It is possible I can't have multiple nesting in a table, but the error seems more as if there was an issue with parsing the JSON itself. I was able to generate and successfully import a json with a simple repeated record (see example below):
{
"eventId": "546",
"eventName": "testEvent",
"eventDetails": [{
"key": "a",
"value": "1"
}, {
"key": "b",
"value": "2"
}, {
"key": "c",
"value": "3"
}]
}
Any advice is appreciated.
There doesn't seem to be anything problematic with your schema, so BigQuery should be able to load your data with your schema.
First, make sure you are uploading newline-delimited JSON to BigQuery. Your example row has many newline characters in the middle of your JSON row, and the parser is trying to interpret each line as a separate JSON row.
Second, it looks like your schema has the key "evenId" in the "event" record, but your example row has the key "eventId".

JSON Schema Validation - Why is required not being enforced?

I've been trying to create a JSON Schema and have been using an online validation tool http://jsonschemalint.com/. I made a change to my JSON object that I expected to fail against my schema but it didn't - so I think I must have made a mistake somewhere. Can anyone explain to my why the following change doesn't cause a validation error?
Schema
{
"title": "Control Configuration Array",
"description": "An array of the configurations",
"type": "array",
"minItems": 1,
"items": {
"group": {
"title": "Control Grouping",
"description": "Represents a logical grouping of controls",
"type": "object",
"properties": {
"value": {
"title": "Group Label",
"description": "The label to use for the group",
"type": "string"
},
"sortIndex": {
"title": "Sort Index",
"description": "The order in which the groups appear",
"type": "number",
"minimum": 0
},
"cssClass": {
"title": "Group CSS",
"description": "The CSS class to apply to the group label",
"type": "string"
},
"controls": {
"title": "Controls",
"description": "The set of controls within this group",
"type": "array",
"minItems": 1,
"required": true,
"items": {
"config": {
"title": "Control Configuration",
"description": "The main configuration object for a control and its associated dependencies",
"type": "object",
"properties": {
"id": {
"title": "Control ID",
"description": "The identifier for the control set which will be used in dependencies",
"type": "string",
"required": true
},
"sortIndex": {
"title": "Sort Index",
"description": "The order in which the controls appear",
"type": "number",
"minimum": 0
},
"label": {
"title": "Label",
"description": "Describes the label for the control group",
"type": "object",
"properties": {
"value": {
"title": "Caption",
"description": "The caption to place in the label",
"type": "string"
},
"cssClass": {
"title": "Label CSS Classes",
"description": "The CSS classes to apply to the label, separated with spaces",
"type": "string"
},
"tooltipText": {
"title": "Tooltip",
"description": "The tooltip to apply to the label and control",
"type": "string"
}
}
},
"control": {
"title": "Control",
"description": "Describes the control for the control group",
"type": "object",
"required": true,
"properties": {
"type": {
"title": "Control Type",
"description": "The type of control that should be displayed",
"type": "string",
"enum": [
"text",
"radio",
"dropdown",
"checkbox",
"color",
"date",
"datetime",
"search",
"email",
"url",
"tel",
"number",
"range",
"month",
"week",
"time",
"datetime-local"
]
},
"options": {
"title": "Avaliable Options",
"description": "The set of avaliable options for all selection controls (e.g. radio, dropdown)",
"type": "array"
},
"value": {
"title": "The current value of the control",
"description": "This is the inital value or selected value of the control",
"type": "object",
"required": true
},
"cssClass": {
"title": "Control CSS Classes",
"description": "The CSS classes to apply to the control, separated with spaces",
"type": "string"
}
}
},
"dependencies": {
"title": "Dependencies",
"description": "Describes the dependencies between this and other controls",
"type": "object",
"properties": {
"enabled": {
"title": "Enabled",
"description": "The properties to determine if the control should be enabled or not",
"type": "object",
"properties": {
"targetID": {
"title": "Enabled Target ID",
"description": "The ID of the target control, whose value must match one of the target values for this control to be enabled",
"type": "string",
"required": true
},
"targetValues": {
"title": "Enabled target values",
"description": "The set of values which if selected in the target control will cause this control to be enabled",
"type": "array",
"required": true
}
}
},
"display": {
"title": "Display",
"description": "The properties to determine if the control should be displayed or not",
"type": "object",
"properties": {
"targetID": {
"title": "Display Target ID",
"description": "The ID of the target control, whose value must match one of the target values for this control to be displayed",
"type": "string",
"required": true
},
"targetValues": {
"title": "Display target values",
"description": "The set of values which if selected in the target control will cause this control to be displayed",
"type": "array",
"required": true
}
}
}
}
},
"validation": {
"title": "Validation",
"description": "Describes the validation of the control value",
"type": "object",
"properties": {
"required": {
"title": "Required",
"description": "Whether the field is required",
"type": "boolean"
},
"min": {
"title": "Minimum",
"description": "The minimum value that the control is allowed",
"type": "number"
},
"max": {
"title": "Maximum",
"description": "The maximum value that the control is allowed",
"type": "number"
},
"minLength": {
"title": "Minimum Length",
"description": "The minimum length that the control is allowed",
"type": "integer"
},
"maxLength": {
"title": "Maximum Length",
"description": "The maximum length that the control is allowed",
"type": "integer"
},
"pattern": {
"title": "Regex Pattern",
"description": "A regex pattern to use for validation",
"type": "string"
},
"step": {
"title": "Increment Step",
"description": "An increment check that must be met - generally combine with min/max",
"type": "number"
},
"email": {
"title": "Email",
"description": "Whether the field must be an email address",
"type": "boolean"
},
"equal": {
"title": "Equals",
"description": "Ensure the field equals the other object",
"type": "object"
},
"notEqual": {
"title": "Not Equals",
"description": "Ensure the field does not equal the other object",
"type": "object"
},
"date": {
"title": "Date",
"description": "Whether the field must be a date",
"type": "boolean"
},
"dateISO": {
"title": "Date ISO",
"description": "Whether the field must be an ISO date",
"type": "boolean"
},
"number": {
"title": "Number",
"description": "Whether the field must be a number",
"type": "boolean"
},
"digit": {
"title": "Digit",
"description": "Whether the field must be a digit",
"type": "boolean"
}
}
}
}
}
}
}
}
}
}
}
JSON
[
{
"value": "Group1",
"cssClass": "red",
"sortIndex": 1,
"controls": [
{
"id": "ConfigType",
"sortIndex": 1,
"label": {
"value": "Configuration Type",
"cssClass": "label",
"tooltipText": "Configuration Type Tooltip"
},
"control": {
"type": "radio",
"options": [
"Single Deck",
"Level"
],
"value": "Single Deck",
"cssClass": "control"
}
},
{
"id": "AppType",
"sortIndex": 2,
"label": {
"value": "Application Type",
"cssClass": "label",
"tooltipText": "Application Type Tooltip"
},
"control": {
"type": "dropdown",
"options": [
"Other",
"Other2"
],
"value": "Other",
"cssClass": "red"
},
"dependencies": {
"enabled": {
"targetID": "ConfigType",
"targetValues": [
"Level"
]
},
"display": {
"targetID": "ConfigType",
"targetValues": [
"Level"
]
}
}
},
{
"id": "textType",
"label": {
"value": "Text Type",
"cssClass": "label",
"tooltipText": "text Type Tooltip"
}
}
]
}
]
Change
Find "targetID" : "ConfigType" under either the enabled or display dependency. Remove this line. This should then fail as these are both required fields according to the schema. However it doesn't seem to fail...
First I would recommend you move to draft 4 which have some improvements (required is provided in an array).
jsonschemalint is using draft 3. Afaik "items" constraint has not changed. You can provide a boolean value, an object or one array of objects.
In your case, you have provided one object-schema but incorrectly. "group" and "config" labels are not necessary. For instance, given the following json object in draft 3:
[{}]
This schema (similar as yours) validates the data:
{
"type" : "array",
"minItems" : 1,
"items" : {
"unnecesaryLabel" : {
"type" : "object",
"properties" : {
"one" : {
"required" : true
}
}
}
}
}
And this makes the data invalid:
{
"type" : "array",
"minItems" : 1,
"items" : {
"type" : "object",
"properties" : {
"one" : {
"required" : true
}
}
}
}