JSON Schema for Dynamsoft Barcode Reader Template Files

If you have tried out Dynamsoft Barcode Reader 6.0, you may have noticed the new template feature. The new SDK version supports importing parameters from JSON-format template files. How to create the template files? One way is to visit the barcode online demo, select some arguments and then download the template file. The other way is to write a JSON file by yourself. When writing a JSON file line by line, there is a problem that how to write valid data. The workaround is JSON Schema. JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. To facilitate developers, I created a basic JSON Schema for Dynamsoft Barcode Reader template files.

JSON Schema for IntelliSense in Visual Studio Code

Visual Studio Code features IntelliSense which helps developers quickly write code. To use IntelliSense for JSON files, you need to configure JSON schema in user settings. Press F1 to open user settings and search for `json schema’. By default, there is an empty array. You can read vscode-docs to learn how to add custom JSON schemas for corresponding JSON files.

JSON schema in VS Code

Get started with examples

Here is a basic example of a JSON schema.

{
    "title": "Person",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string"
        },
        "lastName": {
            "type": "string"
        },
        "age": {
            "description": "Age in years",
            "type": "integer",
            "minimum": 0
        }
    },
    "required": ["firstName", "lastName"]
}

We can visit understanding-json-schema to figure out how these keywords work for JSON.

  • The title must be a string, which is a short description of the purpose of the data. For long words description, you can add a description keyword.
  • The type specifies the data type for a schema. The basic types include string, number, object, array, Boolean and null. For example, assume you set name with the string type, if you create a JSON instance and set name with number type, you will get an error hint.
  • The properties is an object, where each key is the name of a property and each value is a JSON schema used to validate that property.
  • The required keyword takes an array of one or more strings. Each of these strings must be unique. Missing the required property makes the JSON document invalid.

Quickly Creating Dynamsoft Barcode Reader templates in VS Code

Create dbr.json:

{
    "title": "JSON schema for DBR configuration files",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "A representation of Dynamsoft Barcode Reader template.",
    "type": "object",
    "required": ["Version", "ImageParameters"],
    "properties": {
        "Version": {
            "description": "The template version number.",
            "type": "string",
            "enum": [
                "1.0"
            ]
        },
        "ImageParameters": {
            "description": "Parameters for barcode detection",
            "type": "object",
            "required": [
                "Name"
            ],
            "properties": {
                "Name": {
                    "description": "The name of the ImageParameters object",
                    "type": "string",
                    "maxLength": 50,
                    "minLength": 1
                },
                "Description": {
                    "description": "The description of the ImageParameters object",
                    "type": "string"
                },
                "BarcodeFormatIds": {
                    "description": "Sets which types of barcode to be read. Barcode types can be combined",
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "All", "OneD", "CODE_39", "CODE_128", "CODE_93", "CODABAR", "ITF", "EAN_13", "EAN_8", "UPC_A", "UPC_E", "INDUSTRIAL_25", "PDF417", "QR_CODE", "DATAMATRIX"
                        ]
                    }
                },
                "MaxBarcodesCount": {
                    "description": "Sets the maximum number of barcodes to read",
                    "type": "number",
                    "maximum": 2147483647,
                    "minimum": 1,
                    "default": 2147483647
                },
                "Timeout": {
                    "description": "Sets the maximum amount of time (in milliseconds) it should spend searching for a barcode per page",
                    "type": "number",
                    "maximum": 2147483647,
                    "minimum": 0,
                    "default": 2147483647
                },
                "ScaleDownThreshold": {
                    "description": "Sets the threshold value of the image shrinking",
                    "type": "number",
                    "maximum": 2147483647,
                    "minimum": 512,
                    "default": 2048
                },
                "DeblurLevel": {
                    "description": "The blurriness of the barcode",
                    "type": "number",
                    "maximum": 9,
                    "minimum": 0,
                    "default": 5
                }
            }
        }
    }
}

Copy the file to barcode project root directory.

Add the configuration to user settings.

"json.schemas": [
{
    "fileMatch": [
        "/tpl_*.json"
    ],
    "url": "./dbr.json"
}]

Create a template file started with `tpl_’.

Customize your parameter template for Dynamsoft Barcode Reader SDK.

Creating dbr template in Visual Studio Code

Source Code

https://github.com/dynamsoft-dbr/template-json-schema