Scandit Parser Library

The Scandit Parser Library parses data strings, e.g. as found in barcodes, into a set of key-value mappings. These data formats are supported: Health Industry Bar Code (HIBC), GS1 Application Identifier (AI) system, AAMVA Driver License/Identification, ICAO Machine Readable Travel Document (MRTD) and Swiss QR Codes. Currently there are bindings for Android, iOS and JavaScript available.

More binding languages and data formats will be added in future releases. Please contact us if the data format you are using is not supported by the library, or you want to use the Scandit Parser Library on a yet-unsupported platform.

Interested in using the library in your project? Contact us.

Quick Start Guide

Installation: For Android and iOS, the parser library is embedded in the Scandit SDK. For information on how to install it, consult the Scandit SDK documentation.

In a nutshell, the Scandit Parser Library provides functionality to transform a data string and into a list of key-value pairs. To use this functionality in your app, first the parser must be instantiated with the desired format. The result is then returned in a result object. The following two samples show how the parser code typically looks like on the different platforms.

Android Example:

import com.scandit.parser.*;
import org.json.*;
import java.util.HashMap;

...
...

// picker: BarcodePicker object from Scandit SDK
Parser p = picker.createParserForFormat(DataFormat.GS1AI);

ParserResult res = null;
try {
    res = parser.parseString("1719060110SCANDIT123");
} catch (IllegalArgumentException e) {
    // Something went wrong.
}


// We can either acces the data from the raw JSON string ...
Log.d(TAG, res.getJsonString());

// ... or from the fields dictionary ...
HashMap<String, Field> map = res.getFieldsDict();
Field metaField = map.get("17");
Log.d(TAG, metaField.getRaw());
// parsed can be a Map<String,Object>, Object[], Integer, Long, Boolean, Double or String
Object parsed = metaField.getParsed();
Log.d(TAG, metaField.getRaw());
Log.d(TAG, parsed.toString());

// ... or from the fields array
Field[] fields = res.getFieldsArray();
for (int i = 0; i < fields.length; i++) {
    Log.d(TAG, fields[i].getName());
    Log.d(TAG, fields[i].getRaw());
    Object p = fields[i].getParsed();
    Log.d(TAG, p.toString());
}

// Using the parser tools class we can easily extract dates from corresponding fields
Field dateField = map.get("17");
Calendar date = ParserTools.dateFromParsedObject(dateField.getParsed());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Log.d(TAG, format.format(date.getTime()));

For details, go to the Android API docs.

iOS Example:

#import <ScanditParser/ScanditParser.h>

...

NSError *err;
// Replace SBSDataFormatHIBC with the data format of your choice.
// picker: SBSBarcodePicker object from Scandit SDK
SBSParser *parser = [picker parserForFormat:SBSParserDataFormatHIBC error:&err];
if (!parser) {
    // Something went wrong. Look at err for more info.
}

SBSParserResult *result = [parser parseString:@"+A99912345/$$52001510X33" error:&err];
if (!result) {
    // Something went wrong. Look at err for more info.
}

// We can either access the data from the raw JSON string...
NSLog(@"%@", result.jsonString);

// ... or from the fields dictionary...
NSDictionary<NSString*, SBSField*> *fieldsDictionary = result.fieldsDict;
for (NSString *key in fieldsDictionary.allKeys) {
    SBSField *field = [fieldsDictionary objectForKey:key];
    NSLog(@"%@ name: %@", key, field.name);
    NSLog(@"%@ raw: %@", key, field.rawString);
    NSLog(@"%@ parsed: %@", key, field.parsed);
}

// ... or from the fields array
for (SBSField* field in result.fieldsArray) {
    NSLog(@"%@ raw: %@", field.name, field.rawString);
    NSLog(@"%@ parsed: %@", field.name, field.parsed);
}

For details, go to the iOS API docs.

JavaScript Example:

var string = '+A123BJC5D6E71G';
var options = null;
try {
    var result = ScanditParser.parseString(
        ScanditParser.Type.HIBC,
        string,
        options
        );
} catch (e) {
    // Something went wrong
}

// We can directly access the json object ...
console.log(result.json);
// .. or we can acces individual fields by name
var field = result.getFieldByName("metadata");
console.log(field.parsed);
console.log(field.rawString);

For details, go to the JavaScript API docs.

Format-Specific Documentation