
ID Card to JSON in 10 Lines of Python: OCR API + GPT-4o mini
You have a photo of an ID card and you need the data inside it — name, date of birth, document number, expiration — as structured JSON. AWS Textract AnalyzeID does this, but it costs $0.025/doc and only supports US documents. Here's how to do it for any ID card, from any country, in 10 lines of Python — for about $0.013 per document. The Pipeline OCR API extracts raw text from the ID card image GPT-4o mini structures the raw text into label-value pairs No regex, no templates, no per-country configuration. The Code import requests , json from openai import OpenAI def id_card_to_json ( image_path ): # Step 1: OCR ocr = requests . post ( " https://ocr-wizard.p.rapidapi.com/ocr " , headers = { " x-rapidapi-key " : " YOUR_KEY " , " x-rapidapi-host " : " ocr-wizard.p.rapidapi.com " }, files = { " image " : open ( image_path , " rb " )}, ). json () # Step 2: Structure with LLM result = OpenAI (). chat . completions . create ( model = " gpt-4o-mini " , response_format = { " type " : " json_obj
Continue reading on Dev.to Tutorial
Opens in a new tab




