github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/conditions/json_schema.md (about) 1 --- 2 title: json_schema 3 type: condition 4 status: stable 5 --- 6 7 <!-- 8 THIS FILE IS AUTOGENERATED! 9 10 To make changes please edit the contents of: 11 lib/condition/json_schema.go 12 --> 13 14 import Tabs from '@theme/Tabs'; 15 import TabItem from '@theme/TabItem'; 16 17 18 Validates a message against the provided JSONSchema definition to retrieve a 19 boolean response indicating whether the message matches the schema or not. 20 21 22 <Tabs defaultValue="common" values={[ 23 { label: 'Common', value: 'common', }, 24 { label: 'Advanced', value: 'advanced', }, 25 ]}> 26 27 <TabItem value="common"> 28 29 ```yaml 30 # Common config fields, showing default values 31 json_schema: 32 schema: "" 33 schema_path: "" 34 ``` 35 36 </TabItem> 37 <TabItem value="advanced"> 38 39 ```yaml 40 # All config fields, showing default values 41 json_schema: 42 schema: "" 43 schema_path: "" 44 part: 0 45 ``` 46 47 </TabItem> 48 </Tabs> 49 50 If the response is true the condition passes, otherwise it does not. Please 51 refer to the [JSON Schema website](https://json-schema.org/) for information and 52 tutorials regarding the syntax of the schema. 53 54 ## Fields 55 56 ### `schema` 57 58 A schema to apply. Use either this or the `schema_path` field. 59 60 61 Type: `string` 62 Default: `""` 63 64 ### `schema_path` 65 66 The path of a schema document to apply. Use either this or the `schema` field. 67 68 69 Type: `string` 70 Default: `""` 71 72 ### `part` 73 74 The index of a message within a batch to test the condition against. This 75 field is only applicable when batching messages 76 [at the input level](/docs/configuration/batching). 77 78 Indexes can be negative, and if so the part will be selected from the end 79 counting backwards starting from -1. 80 81 82 Type: `number` 83 Default: `0` 84 85 ## Examples 86 87 With the following JSONSchema document: 88 89 ``` json 90 { 91 "$id": "https://example.com/person.schema.json", 92 "$schema": "http://json-schema.org/draft-07/schema#", 93 "title": "Person", 94 "type": "object", 95 "properties": { 96 "firstName": { 97 "type": "string", 98 "description": "The person's first name." 99 }, 100 "lastName": { 101 "type": "string", 102 "description": "The person's last name." 103 }, 104 "age": { 105 "description": "Age in years which must be equal to or greater than zero.", 106 "type": "integer", 107 "minimum": 0 108 } 109 } 110 } 111 ``` 112 113 And the following Benthos configuration: 114 115 ``` yaml 116 json_schema: 117 schema_path: "file://path_to_schema.json" 118 ``` 119 120 If the message being processed looked like: 121 122 ``` json 123 {"firstName":"John","lastName":"Doe","age":21} 124 ``` 125 126 Then the condition would pass. 127