Schema Tax

W2 Extraction API: Getting Typed W-2 Fields as JSON

By Schema TaxPublished Updated

A W2 extraction API reads a W-2 image or PDF and returns one JSON record per form, with a named, typed field for every box from the employee's SSN in Box a to the locality name in Box 20. Box 12 codes and state lines come back as arrays, and rate checks show whether the read holds together.

What a W2 extraction API returns for each W-2 box

A W2 extraction API returns one field per W-2 box, each with a fixed name, a type and the box label it came from. Identity boxes a to f become text and masked TINs, Boxes 1 to 11 become money fields, Box 13 becomes three booleans, and Boxes 12 and 15 to 20 become arrays of rows.

The table below maps the boxes on the 2026 Form W-2 to example field names and types, with values from one fictional W-2. The field names are illustrative. Schema Tax has no public API documentation, so treat them as a pattern to copy or adapt, not as a published format.

BoxLabel on the 2026 formExample field nameTypeExample value
aEmployee's social security numberemployee_ssnmasked TINXXX-XX-1234
bEmployer identification number (EIN)employer_einmasked TINXX-XXX8810
cEmployer's name, address, and ZIP codeemployerobject (name, address)Cedar Point Dental Group LLC
dControl numbercontrol_numbertext or nullnull
e, fEmployee's name and addressemployeeobject (first, last, suffix, address)Jordan Sample
1Wages, tips, other compensationwagesmoney64000.00
2Federal income tax withheldfederal_income_tax_withheldmoney7420.00
3Social security wagessocial_security_wagesmoney68000.00
4Social security tax withheldsocial_security_tax_withheldmoney4216.00
5Medicare wages and tipsmedicare_wagesmoney68000.00
6Medicare tax withheldmedicare_tax_withheldmoney986.00
7Social security tipssocial_security_tipsmoney or nullnull
8Allocated tipsallocated_tipsmoney or nullnull
9(shaded, no label)nonenonenone
10Dependent care benefitsdependent_care_benefitsmoney or nullnull
11Nonqualified plansnonqualified_plansmoney or nullnull
12a to 12dSee instructions for box 12box12array of {code, amount}[{"code":"D","amount":"4000.00"},{"code":"DD","amount":"7850.00"}]
13Statutory employee, Retirement plan, Third-party sick paystatutory_employee, retirement_plan, third_party_sick_paybooleanfalse, true, false
14aOtherbox14_otherarray of {label, amount}[]
14bTreasury Tipped Occupation Code(s)tipped_occupation_codesarray of text[]
15 to 20State, employer's state ID, state wages, state income tax, local wages, local income tax, locality namestate_linesarray of rowstwo rows, shown below

In this example, Box 1 is $4,000 lower than Box 3 because of the code D amount in Box 12. The IRS General Instructions for Forms W-2 and W-3 say elective deferrals such as 401(k) employee contributions are generally left out of Box 1, while Box 3 shows wages before payroll deductions. A W2 extraction API does not judge whether that gap is right. It reports both numbers faithfully so your code or a reviewer can.

Box 9 deserves a note. The 2026 form prints it as a shaded box with no label, so a schema has nothing to name. Leaving it out is better than inventing a placeholder field that is always empty.

What each W-2 box means for the employee, from wages to dependent care, is covered in the W-2 forms category. This post sticks to how the boxes are shaped as data.

W2 JSON schema for Box 12 code pairs and state lines

A W2 JSON schema should store Box 12 and the state and local boxes as arrays, not numbered keys. Box 12 holds up to four code and amount pairs, and Boxes 15 to 20 hold up to two state rows and two locality rows. Arrays keep one shape whether a form uses one row or four.

The W-2 instructions describe Box 12 as an IRS code in capital letters followed by the dollar amount, with "decimal points but not dollar signs or commas". That maps cleanly to a pair: a code string and an amount money string. A fixed list of keys such as box12a_code, box12a_amount, box12b_code and so on forces client code to loop over letter suffixes and to treat the position as meaningful, when the instructions do not attach meaning to which slot a code lands in.

The 2026 instructions also add codes. They describe new code TP for cash tips reported to the employer, code TT for qualified overtime compensation, and code TA for employer contributions to Trump accounts. A schema that validates codes against a list needs a list per tax year, so an older parser does not reject a 2026 form for using a code it has never seen. What each code means for the employee belongs to the W-2 Box 12 codes category.

Here is an illustrative JSON fragment for the fictional W-2, posted to a placeholder URL. The endpoint https://api.example.com is an example only and is not a Schema Tax endpoint.

POST https://api.example.com/v1/w2
Content-Type: application/pdf
{
  "form_type": "W-2",
  "tax_year": 2026,
  "box12": [
    { "box": "12a", "code": "D", "amount": "4000.00" },
    { "box": "12b", "code": "DD", "amount": "7850.00" }
  ],
  "state_lines": [
    { "state": "OR", "state_employer_id": "0123456-7", "state_wages": "44000.00", "state_income_tax": "3170.00", "local_wages": null, "local_income_tax": null, "locality_name": null },
    { "state": "ID", "state_employer_id": "000987654", "state_wages": "20000.00", "state_income_tax": "1050.00", "local_wages": null, "local_income_tax": null, "locality_name": null }
  ]
}

Each Box 12 row keeps its slot label (12a, 12b) as metadata, so a reviewer can find it on the page, but the meaning lives in code. Each state row keeps the state wages and the state tax together. The instructions say the state and local boxes can report "two states and two localities", with each separated by a broken line on the form, so one row per line on the form is the natural unit.

Envelope fields such as document ID and tax year, and the naming rules behind these field names, are covered in the guide to designing a tax form JSON schema.

How does a W2 OCR API handle several W-2s in one PDF?

A W2 OCR API handles a PDF of several W-2s by returning one record per form, each with its own page range. Two employers produce two records. Two copies of the same W-2 on one sheet should produce one record, with the duplicate noted, so totals do not count the same wages twice.

Several W-2s in one file is the normal case for anyone who has more than one job in a year or handles forms for a household. A W2 OCR API first has to find where one form ends and the next begins. The employer EIN, the employee's masked SSN and the tax year together usually identify a form. Two pages with different EINs are two forms.

Copies of the same form are harder. Employers often hand out a sheet with several copies of one W-2 on it, labeled for different uses. The post on W-2 Copy B, Copy C and Copy 2 explains what each copy is for. For data purposes they are the same record. A service that reads all of them should return the first as the record and mark the others as duplicates of it, or return them grouped, so a sum over the response gives the right total.

A reissued form is another case. The W-2 instructions say that when an employee loses a W-2, the employer writes "REISSUED STATEMENT" on the new copy. If a PDF holds both the lost original and its reissue, they carry the same numbers and should collapse to one record, with a note that one copy is a reissue.

A corrected W-2c is a different form, not a copy. The post on the corrected W-2c describes how it differs. A W2 extraction API that does not read the W-2c should classify it and return no fields rather than treat it as a W-2.

Which W2 parsing API checks catch a bad read?

A W2 parsing API catches most misreads with a few checks the form itself supports. Box 4 should be 6.2% of Box 3, Box 6 should be 1.45% of Box 5, and the EIN in Box b should follow the XX-XXXXXXX pattern. A value that fails is a reason to look at the page again.

The rates come straight from the IRS. The W-2 instructions show social security tax as 6.2% of the amount in Box 3 and Medicare tax as 1.45% of the amount in Box 5. In the fictional example, $68,000.00 times 6.2% is $4,216.00, and times 1.45% is $986.00. Both match the extracted values, which is strong evidence that the digits in four boxes were read correctly at once. A dropped digit or a 3 read as an 8 would break the ratio.

A cap check adds a second line of defense. The same instructions say the total of Boxes 3 and 7 cannot exceed $184,500, the 2026 social security wage base, and that Box 4 should not exceed $11,439 for 2026. A Box 3 of $1,840,500 is almost certainly an extra digit, and the cap catches it even when Box 4 was misread the same way.

The EIN pattern check is simple and catches a different class of error. The W-2 instructions write the EIN as XX-XXXXXXX: two digits, a hyphen, seven digits. An EIN with eight digits, or with a letter where a digit belongs, means the OCR misread the box or picked up a nearby number.

Each check needs a tolerance. Employers round to the cent, so a computed tax may differ by a cent or two from the printed one. Treat a difference within a few cents as a pass and anything larger as a flag. Schema Tax runs these same rate and pattern checks during its validate step, described in how Schema Tax reads a form in five steps, and flags uncertain values for a person to confirm.

The full set of W-2 math checks, including how Box 1 relates to Box 3 and what tolerance to pick, is covered in the post on checking W-2 math.

W2 extraction API edge cases: blank boxes, Box 12 overflow and duplicate copies

W2 extraction API edge cases come down to three questions: is an empty box blank or unread, does one employee's data span two forms, and is a second page a new form or a copy. Each needs an explicit answer in the JSON, because guessing silently produces wrong totals.

Blank boxes

Most W-2s leave several boxes empty. Boxes 7, 8, 10 and 11 are blank for many employees. A blank money box should come back as null with a status of blank, never as zero. Zero and empty mean different things, and once a null becomes a zero in your database you cannot tell them apart.

Box 12 overflow

The W-2 instructions say no more than four items go in Box 12 on Copy A, and that more items go on a separate Form W-2. So one employee can have two W-2s from the same employer for the same year, where the second carries only extra Box 12 codes. A W2 extraction API should return both records, because both are real forms. Your code then decides whether to merge them. A safe merge rule: same EIN, same masked SSN, same tax year, and the second form's wage boxes blank or identical.

More than two states

The same overflow rule applies to state lines. The instructions say to prepare a second Form W-2 when there are more than two states or localities. Expect a second record with only state rows filled in, and merge it the same way as a Box 12 overflow.

When the Medicare check fails on a correct form

A higher earner's Box 6 can exceed 1.45% of Box 5 on a correct form. The W-2 instructions say employers withhold an additional 0.9% Medicare tax on wages over $200,000 in a calendar year. A check that does not allow for this will flag every high earner's W-2. Adjust the expected rate above that wage level instead of treating the flag as an error.

Masked numbers

An SSN printed as XXX-XX-1234 is normal. The instructions let employers truncate the employee's SSN on employee copies by replacing the first five digits with asterisks or Xs. A service that masks numbers before storage returns the same format even when the page shows all nine digits.

Other forms raise their own shape questions. The 1099 extraction API guide covers NEC, MISC, INT and DIV fields, and the 1099-B JSON format for lots and wash sales shows how to hold a brokerage statement with many sales.

All posts in Tax Form APIs for Developers