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