National ID OCR API for Go: Raw HTTP for Maximum Control
Achieve 99.7% field-level accuracy and sub-1500ms via a Hybrid Vision AI & MRZ Validation engine for real-time KYC.

Why National ID OCR is Difficult
Open-source OCR engines like Tesseract fail on real-world National ID documents. The core challenge is variability: inconsistent lighting creates glare and shadows, while mobile captures introduce skew and rotation. These image defects cripple template-based approaches. Furthermore, parsing the output requires maintaining brittle RegEx patterns for dozens of document layouts, a significant engineering overhead. Manually implementing validation for checksums, such as those in a Machine-Readable Zone (MRZ), is error-prone and complex. These factors combine to create a high-maintenance, low-accuracy system unsuitable for production KYC workflows.
Enterprise-Grade Extraction with StructOCR
StructOCR bypasses the limitations of generic OCR. Our id parsing api is powered by pre-trained Deep Learning models specifically architected for identity documents. Upon receiving an image, our system performs automatic pre-processing, including deskewing, denoising, and glare removal. This normalized image is then processed by our specialized models which locate and extract specific data fields—not just raw text lines. Unlike Tesseract's raw text dump, we deliver a standardized JSON output with validated fields (e.g., `date_of_birth`), eliminating the need for complex post-processing logic on your end, and ensuring adherence to standards like the 14 digits structure where applicable.
Production Use Cases
- Digital Onboarding (KYC): Reduce drop-off rates by pre-filling user data from National IDs in < 2 seconds.
- Fraud Prevention: Detect tampered fonts or mismatched MRZ checksums automatically.
- Global Compliance: Handle National IDs from 200+ jurisdictions without custom rules.
Live Demo: ID card scanner
No registration required. Upload a file to test the extraction.
Drop files here or click to browse
JPG · PNG · WebP · up to 500 files · max 4.5 MB each
Implementation: Go (Golang)
The following Go code provides a robust implementation. It handles file reading, Base64 encoding, and parses the region-specific JSON fields (like CNP, CPF, or NIN) into native Go structs.
Prerequisite: Go 1.16+
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
// 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
// 👉 https://structocr.com/register
// --- Struct Definitions ---
type ApiResponse struct {
Success bool `json:"success"`
Data NationalIdData `json:"data"`
Error string `json:"error,omitempty"`
}
type NationalIdData struct {
CountryCode string `json:"country_code"`
DocumentNumber string `json:"document_number"`
PersonalNumber string `json:"personal_number"`
CardSeries string `json:"card_series"`
Surname string `json:"surname"`
GivenNames string `json:"given_names"`
Sex string `json:"sex"`
DateOfBirth string `json:"date_of_birth"`
Address string `json:"address"`
Additional AdditionalFields `json:"additional_fields"`
}
type AdditionalFields struct {
MrzLine1 string `json:"mrz_line_1"`
MrzLine2 string `json:"mrz_line_2"`
MrzLine3 string `json:"mrz_line_3"`
}
func main() {
apiURL := "https://api.structocr.com/v1/national-id"
apiKey := "YOUR_API_KEY_HERE"
imagePath := "id_card.jpg"
imageBytes, err := os.ReadFile(imagePath)
if err != nil { return }
base64Image := base64.StdEncoding.EncodeToString(imageBytes)
payload, _ := json.Marshal(map[string]string{"img": base64Image})
req, _ := http.NewRequest("POST", apiURL, bytes.NewBuffer(payload))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil { return }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var result ApiResponse
if err := json.Unmarshal(body, &result); err != nil { return }
if result.Success {
data := result.Data
fmt.Println("✅ National ID Extracted!")
fmt.Printf("Doc Number: %s\n", data.DocumentNumber)
fmt.Printf("Name: %s %s\n", data.GivenNames, data.Surname)
if data.Additional.MrzLine1 != "" {
fmt.Printf("MRZ Line 1: %s\n", data.Additional.MrzLine1)
fmt.Printf("MRZ Line 2: %s\n", data.Additional.MrzLine2)
}
}
}Technical Specs
- •Latency: < 4s (Average)
- •Uptime: 99.9% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Base64 Encoded)
- •Max File Size: 4.5MB
- •Output: JSON (Structured Data)
Key Features
- •Hybrid VIZ + MRZ AI: Cross-validates unstructured visual data against cryptographic MRZ checksums (TD1/TD2) for zero hallucination.
- •Specialized Numbers: Extracts region-specific IDs like CNP (Romania), CPF (Brazil), and NIN (Nigeria).
- •Multi-line Addresses: Intelligently reconstructs full addresses from fragmented lines on ID cards.
Sample JSON Output
StructOCR returns a normalized JSON object containing both Visual Zone (VIZ) extraction and raw Machine-Readable Zone (MRZ) lines.
{
"success": true,
"data": {
"type": "national_id",
"country_code": "ROU",
"nationality": "ROMANA",
"document_number": "123456",
"card_series": "KS",
"personal_number": "1920319123456",
"surname": "POPESCU",
"given_names": "ANDREI",
"sex": "M",
"date_of_birth": "1992-03-19",
"place_of_birth": "Jud. CS Mun. Reșița",
"address": "Jud. CS Orș. Bocșa Str. Nucilor Nr. 15",
"date_of_issue": "2020-05-10",
"date_of_expiry": "2030-05-10",
"issuing_authority": "SPCLEP Bocșa",
"additional_fields": {
"phone_number": null,
"tramite_number": null,
"ejemplar": null,
"mrz_line_1": "IDROU123456<0<<<<<<<<<<<<<<<<",
"mrz_line_2": "9203195M3005108ROU19203191234562",
"mrz_line_3": null
}
}
}Frequently Asked Questions
Do you support Machine Readable Zones (MRZ) on ID cards?
Yes! Our engine natively supports ICAO 9303 standard MRZ formats (TD1/TD2) found on many global ID cards. Our Hybrid architecture extracts both the raw MRZ lines and cross-validates them against the Visual Zone (VIZ) for maximum accuracy.
How does StructOCR compare to AWS Textract or Google Vision?
General-purpose OCR services return unstructured lines of text and their coordinates. StructOCR is a specialized service that understands the layout and fields of identity documents. We return a structured JSON object with labeled fields like 'surname' and 'date_of_birth', eliminating the need for you to build and maintain parsing logic.
Do you store the uploaded images?
No. Images are processed in-memory and are purged immediately after the API request is completed. We do not persist Personally Identifiable Information (PII).
How to handle blurry images?
Our API includes an automated image enhancement pipeline that performs deskewing, denoising, and contrast correction before the core OCR engine runs. This significantly improves accuracy on sub-optimal or blurry images common in mobile uploads.
You May Also Like
Related tutorials, platform guides, and comparisons
Nigeria National ID OCR with Node.js SDK
Extract National Identification Number (NIN), names, dates and other visible fields from National Identity Card with the StructOCR Node.js SDK and Express.
Kenya National ID (Maisha Card) OCR Python SDK
Python Tutorial: Automate KYC in Kenya. Extract data, Maisha Namba (UPI), and validate TD1 MRZ from National ID (Maisha Card) using StructOCR Python SDK.
Ukraine National ID OCR Python SDK
Python Tutorial: Automate KYC in Ukraine. Extract data from National ID using StructOCR Python SDK. Supports native text and MRZ extraction.
Egypt ID OCR API & Python SDK
Python Tutorial: Automate KYC in Egypt. Extract data from National IDs using our SDK. Upload an image to test our ID OCR engine live for free.
Philippines PhilID OCR with Node.js SDK
Extract PhilSys Card Number, names, dates and other visible fields from Philippine Identification Card (PhilID) with the StructOCR Node.js SDK and Express.
UAE Emirates ID OCR with Node.js SDK
Extract Emirates ID number, names, dates and other visible fields from Emirates ID with the StructOCR Node.js SDK and Express.
Java National ID Parser API
Upload an image for a free test! Eliminate manual data entry for national IDs. Our Java ID card parsing API provides AES-256 encrypted JSON output in <4s average latency, ensuring SOC2 compliant verification.
Tunisia CIN (Carte d'Identité Nationale) OCR Python SDK
Python Tutorial: Automate KYC in Tunisia. Extract data from CIN (Carte d'Identité Nationale) using StructOCR Python SDK. Supports native text.
Malaysia MyKad OCR with Node.js SDK
Extract identity number, names, dates and other visible fields from MyKad with the StructOCR Node.js SDK and Express.
Indonesia KTP OCR with Node.js SDK
Extract NIK, names, dates and other visible fields from Kartu Tanda Penduduk (KTP) with the StructOCR Node.js SDK and Express.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add National ID OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Bolt.new app. Build KYC and identity verification flows right in your browser.
Add National ID OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API using the Cursor AI code editor. Build KYC and identity verification flows rapidly.
Add National ID OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Lovable.dev app. Build KYC and identity verification flows with zero backend.
Add National ID OCR to Your Replit App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Replit application. Build KYC and identity verification flows using Replit Agent and Secrets.
Add National ID OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a v0 by Vercel app. Build KYC and identity verification flows with zero backend.
Add Receipt OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR receipt API using the Cursor AI code editor. Build expense tracking and receipt scanning tools rapidly.
From tutorial to production in 5 minutes.
You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.