MRZ Parser and Generator API
Parse and validate the machine readable zone of passports, ID cards and visas (TD1, TD2, TD3, MRV-A/B), check digits, or generate an MRZ from data.
Send the 2 or 3 lines of an MRZ as mrz (newlines, an array, or one string of 88 / 90 / 72 characters; spaces and « are cleaned) — the text that passport readers, OCR SDKs and hotel check-in scanners output. The format is detected: TD3 passports, TD1 identity cards (3 × 30), TD2 (2 × 36), MRV-A and MRV-B visas (ICAO Doc 9303 Part 7), plus French ID cards and Swiss / French driving licences. You get the document code and type, issuing state and nationality (ICAO codes with English and Vietnamese names, including D, XXA stateless, UN and EU codes), surname and given names, document number (long TD1 numbers rebuilt from the optional data), birth and expiry dates as ISO dates with age, expired and days to expiry, sex, personal number and optional data.
Each check digit (document number, birth date, expiry, personal number, composite) is recomputed with the 7-3-1 weights and reported with the expected value; autocorrect=true fixes common OCR confusions (O/0, I/1, B/8, S/5, Z/2, G/6) by field type. For Vietnamese chip ID cards (CCCD / thẻ căn cước, IDVNM) the 12-digit personal number in the optional data is decoded (province, century / sex, birth year) and cross-checked.
op=create builds an MRZ from format (TD1, TD2, TD3, MRVA, MRVB), issuing_state, last_name + given_names (or a Vietnamese full_name, family name first), document_number, nationality, birth_date, sex, expiry_date and optional data: names are transliterated to the ICAO form (Vietnamese diacritics removed, Đ → D, Ä → AE…) and truncated by the ICAO rules, check digits computed, and the result parsed back. Nothing is stored or logged; a valid MRZ does not prove a document is genuine.
Markdown · OpenAPI · Postman · llms.txt
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
mrz | body|query | string | yes | The MRZ lines (newline separated, an array, or one string). Required for parsing. | |
autocorrect | body|query | boolean | no | false | Fix OCR letter / digit confusions by field type. |
op | body|query | string | no | parse | parse, create or check-digit (with value). |
format | body | string | no | TD3 | create: TD1, TD2, TD3, MRVA or MRVB. |
document_code | body | string | no | create: P, PN, I, ID, AC, V… (default P for TD3, I for cards, V for visas). | |
issuing_state | body | string | no | create: ICAO / ISO alpha-3 code (VNM) or alpha-2 (VN). | |
last_name | body | string | no | create: primary identifier (surname). | |
given_names | body | string | no | create: secondary identifier. | |
full_name | body | string | no | create: Vietnamese full name, family name first (alternative to last_name + given_names). | |
document_number | body | string | no | create: document number (9 characters; longer in TD1 / TD2). | |
nationality | body | string | no | create: nationality code (default: issuing state). | |
birth_date | body | string | no | create: YYYY-MM-DD. | |
sex | body | string | no | create: M, F or X. | |
expiry_date | body | string | no | create: YYYY-MM-DD. | |
personal_number | body | string | no | create (TD3): personal number, up to 14 characters. | |
optional_data | body | string | no | create: optional data (TD1 line 1, TD2, visas); optional_data_2 for TD1 line 2. | |
vn_cccd | body | string | no | create (TD1): Vietnamese 12-digit personal number; fills the document number and optional data like issued cards. |
Example
curl -X POST "https://apibox.io.vn/v1/mrz" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"mrz":"P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<\nL898902C36UTO7408122F1204159ZE184226B<<<<<10"}'const res = await fetch('https://apibox.io.vn/v1/mrz', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"mrz": "P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<\nL898902C36UTO7408122F1204159ZE184226B<<<<<10"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/mrz",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"mrz": "P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<\nL898902C36UTO7408122F1204159ZE184226B<<<<<10"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/mrz');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"mrz":"P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<\\nL898902C36UTO7408122F1204159ZE184226B<<<<<10"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"format": "TD3",
"document_type": "passport",
"valid": true,
"checks_valid": true,
"fields": {
"document_code": "P",
"issuing_state": {
"code": "UTO",
"alpha2": null,
"name": "Utopia (ICAO specimen)",
"name_vi": "Utopia (mẫu của ICAO)"
},
"last_name": "ERIKSSON",
"given_names": "ANNA MARIA",
"document_number": "L898902C3",
"nationality": {
"code": "UTO",
"alpha2": null,
"name": "Utopia (ICAO specimen)",
"name_vi": "Utopia (mẫu của ICAO)"
},
"birth_date": "1974-08-12",
"sex": "female",
"expiry_date": "2012-04-15",
"personal_number": "ZE184226B",
"optional_data": null
},
"age": 52,
"expired": true,
"days_to_expiry": -5323,
"checks": [
{
"field": "document_number",
"valid": true,
"expected": "6",
"found": "6"
},
{
"field": "birth_date",
"valid": true,
"expected": "2",
"found": "2"
},
{
"field": "expiry_date",
"valid": true,
"expected": "9",
"found": "9"
},
{
"field": "personal_number",
"valid": true,
"expected": "1",
"found": "1"
},
{
"field": "composite",
"valid": true,
"expected": "0",
"found": "0"
}
],
"errors": [],
"specimen": true,
"lines": [
"P<UTOERIKSSON<<ANNA<MARIA<<<<<<<<<<<<<<<<<<<",
"L898902C36UTO7408122F1204159ZE184226B<<<<<10"
]
}
Use cases
- Hotels and homestays: read passports from a scanner for guest registration of foreigners
- Validate MRZ text from an OCR or eKYC SDK before saving it
- Generate test MRZs for document readers and booking systems
- Check expiry dates of travel documents in visa and HR software
FAQ
Does it read images?
No, it reads MRZ text. Use your scanner or an OCR SDK to get the text, then send it here.
Why is the issuing state of the sample "UTO"?
Utopia is the fictitious state of ICAO specimens; it is accepted and flagged with specimen=true.
How are Vietnamese names written?
Without diacritics, Đ as D, family name first: NGUYEN<<THI<ANH<TUYET. Long names are shortened from the last given name.
Related APIs
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
{ }JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.