Schema Tax

W2 to JSON: Field Names for Every Box

By Schema TaxPublished Updated

To turn a W2 into JSON, give every box a fixed field name and a type: strings for the EIN, masked SSN and names, decimal strings or integer cents for money, booleans for the Box 13 checkboxes, and arrays for Box 12 codes and state lines. One JSON object then holds one complete form that any program can read.

A W2 JSON object, box by box

A W2 JSON object holds one Form W-2 as named fields grouped the way the form groups them: the employee, the employer, the federal amounts, the coded items, the checkboxes and the state and local lines. The example below is fictional, with made-up names, amounts and identifiers, and shows one shape that covers every box.

The box list follows the IRS General Instructions for Forms W-2 and W-3 for 2026, including the split Box 14 described in the overview of W2 boxes 12, 13 and 14. The instructions say not to enter an amount in Box 9, so the object has no Box 9 field.

{
  "form_type": "W-2",
  "tax_year": 2026,
  "employee": {
    "ssn_last4": "1234",
    "name": "Jordan Example",
    "address": "88 Sample Rd, Springfield, ST 00000"
  },
  "employer": {
    "ein": "12-3456789",
    "name": "Northwind Example Inc",
    "address": "1 Example Plaza, Springfield, ST 00000",
    "control_number": null
  },
  "box1_wages": "64250.00",
  "box2_federal_withheld": "7015.00",
  "box3_ss_wages": "68000.00",
  "box4_ss_withheld": "4216.00",
  "box5_medicare_wages": "68000.00",
  "box6_medicare_withheld": "986.00",
  "box7_ss_tips": null,
  "box8_allocated_tips": null,
  "box10_dependent_care": null,
  "box11_nonqualified_plans": null,
  "box12": [
    { "code": "D", "amount": "3750.00" },
    { "code": "DD", "amount": "8400.00" }
  ],
  "box13": {
    "statutory_employee": false,
    "retirement_plan": true,
    "third_party_sick_pay": false
  },
  "box14a_other": [
    { "label": "UNION DUES", "amount": "420.00" }
  ],
  "box14b_tipped_occupation_codes": [],
  "state_lines": [
    {
      "state": "ST",
      "state_employer_id": "0012345",
      "box16_state_wages": "64250.00",
      "box17_state_tax": "2890.00",
      "box18_local_wages": null,
      "box19_local_tax": null,
      "box20_locality": null
    }
  ]
}

Read the object top to bottom and it mirrors the paper form. Boxes a to f become the employee and employer objects. Boxes 1 to 11 are flat fields whose names start with the box number. Box 12, Box 14a and the state lines are arrays because they repeat. The null values mark boxes that are blank on this form, a choice explained under W2 JSON pitfalls: float cents and missing versus zero.

For what each amount means on the form, the guide to W2 Boxes 1 through 6, the wage and tax pairs is the place to look. This post covers the data shape, not the tax meaning.

W2 JSON field names and types

W2 JSON field names should carry the box number and a short meaning, and each field should have one type that never changes between forms. Identifiers such as the EIN are strings, money is a decimal string or integer cents, checkboxes are booleans, and repeating boxes are arrays. A consumer can then validate every form against the same rules.

The field table

Field name (example)BoxJSON typeWhy that type
employee.ssn_last4astringLast four digits only; a string keeps a leading zero
employer.einbstringHas a hyphen and may start with 0
employer.name, employer.addresscstringFree text
employer.control_numberdstring or nullOptional on the form
employee.name, employee.addresse, fstringFree text
box1_wages1decimal stringMoney; a string avoids float errors
box2_federal_withheld2decimal stringMoney
box3_ss_wages, box4_ss_withheld3, 4decimal stringMoney
box5_medicare_wages, box6_medicare_withheld5, 6decimal stringMoney
box7_ss_tips, box8_allocated_tips7, 8decimal string or nullOften blank
box10_dependent_care10decimal string or nullOften blank
box11_nonqualified_plans11decimal string or nullOften blank
box12[]12a to 12darray of objectsCode plus amount, repeats
box13.*13booleanThree checkboxes
box14a_other[]14aarray of objectsLabel plus amount, repeats
box14b_tipped_occupation_codes[]14barray of stringsUp to two codes
state_lines[]15 to 20array of objectsUp to two per paper form

Why the EIN is a string

An EIN looks like a number but behaves like a label. The IRS instructions give its format as XX-XXXXXXX and say an EIN may never be truncated. You never add two EINs together, and a leading zero is part of the value. Stored as a JSON number, 04-1234567 would have to drop its hyphen, and its leading zero too, because the number grammar in RFC 8259 does not allow one. State employer IDs and the last four SSN digits follow the same logic.

Why names start with the box number

A field called wages is ambiguous once a system holds W-2s next to 1099s, where Box 1 means something else. A name like box1_wages ties the value to its box and its meaning at once, so a reader of the JSON can check it against the paper form without a lookup table.

How should W2 JSON nest Box 12 entries and state lines?

W2 JSON should nest Box 12 entries and state lines as arrays of small objects, one object per item. Each Box 12 object holds a code and an amount. Each state object holds the state, the employer's state ID, state wages and state tax, plus the local fields. Arrays fit because both parts of the form repeat.

The paper form sets the counts. The IRS General Instructions for Forms W-2 and W-3 say not to enter more than four items in Box 12 on Copy A, and to issue a second Form W-2 for more. Boxes 15 to 20 hold two states and two localities, with a second W-2 for more than two. Fixed fields such as box12a_code through box12d_amount mirror one paper form, but they break when a second W-2 from the same employer carries the overflow.

An array avoids that. You append the items from the second form to the same list, or keep two objects and merge them later. Code that reads the array loops over it instead of checking four named slots for blanks.

What each item holds

A Box 12 item needs only code and amount. The code is a string such as "D" or "DD", because codes are letters, and new ones appear, such as the three added for 2026, which a fixed enumeration in old code would reject. Validate codes against a list you update each year rather than a list compiled into the program.

A state item keeps the state and local lines together, because Box 15 identifies the state and Boxes 16 and 17 report wages and tax for that state. Splitting state wages and state tax into separate arrays would let them fall out of step. Keeping each line as one object means the wage and its tax always travel together.

When several W-2s are combined, these arrays are also what make totals harder than they look. Summing all Box 12 amounts mixes unrelated codes. The guide to multiple W2s in one spreadsheet shows which values add up across forms and which do not.

Which W2 JSON fields should be masked?

The W2 JSON field that should always be masked is the employee's Social Security number, kept as its last four digits only. The employer EIN stays complete, because it identifies a business rather than a person and the IRS says it may not be truncated. Names and addresses stay readable when the consumer needs them.

The IRS sets the precedent for the SSN. The IRS General Instructions for Forms W-2 and W-3 allow employers to truncate the SSN on employee copies, for example as ***-**-1234, while Copy A sent to the Social Security Administration must show the full number. Most uses of W-2 JSON outside payroll, such as budgeting, income checks or reconciling forms, never need the other five digits.

Store the masked value in its own field, such as ssn_last4, rather than keeping a full-SSN field and hiding it at display time. A field that holds only four digits cannot leak nine. If a workflow truly needs the full number, keep it in a separate, access-controlled system and link by a form ID.

The four digits are still useful. They let a person confirm that a form belongs to them, and they help tell apart two people with the same name in one household file.

Schema Tax follows this pattern: it masks SSNs and TINs to the last four digits before anything is written to storage, so the JSON it exports never held the full number. Its security commitments on the homepage list the other three, covering encryption, retention and training.

W2 JSON pitfalls: float cents and missing versus zero

The two most common W2 JSON pitfalls are storing money as floating-point numbers and treating a blank box as zero. Floats can turn 0.10 plus 0.20 into a value that is not exactly 0.30, and a zero that should be null hides the difference between a box the employer left blank and a box that truly reports no money.

Money without float errors

JSON itself does not fix the precision of numbers. RFC 8259, the JSON specification, says implementations may set limits on the range and precision of numbers they accept, and that good interoperability comes from expecting no more precision than IEEE 754 double-precision numbers provide. It adds that integers in the range from -(2^53)+1 to (2^53)-1 are interoperable.

That leaves two safe options for W-2 amounts:

  • Decimal strings, such as "64250.00". They read exactly as printed on the form, and the consumer converts them with a decimal type. This is the choice in the example above.
  • Integer cents, such as 6425000. They are exact as long as they stay inside the interoperable integer range, which any W-2 amount does.

Either works. Pick one, document it, and never mix them in one file. The IRS instructions tell employers not to omit cents or the decimal point on the form, so keep two decimal places in a decimal string even for whole-dollar amounts.

Missing versus zero

A blank Box 7 and a Box 7 of 0.00 can mean different things to a consumer. Use null for a box that is blank on the form and "0.00" only when the form shows a zero. Code that totals fields should skip nulls, and code that validates should flag a required field, such as Box 1, that comes back null.

Arrays follow the same idea in a different form. An empty box12 array means there were no Box 12 items, which is common and correct. A missing box12 key means the extractor did not produce the field, which is a bug to investigate.

Who uses W2 JSON?

W2 JSON is used by software rather than by people reading a page: budgeting and personal finance apps, lending and income checks, payroll reconciliation scripts, document pipelines at accounting firms, and internal tools that load forms into a database. Anyone who would otherwise copy box values into code by hand can read the JSON instead.

Scripts are the simplest case. A short program can loop over a folder of W-2 objects, total Box 1 per employer, and check that each Box 4 equals 6.2% of Box 3, the Social Security tax rate in the IRS General Instructions for Forms W-2 and W-3. Fixed field names make that loop the same for every form.

Applications are the larger case. An app that asks users to upload a W-2 needs the data in a predictable shape, and the box-named object above is that shape. An API fits here: the app sends the file and gets the JSON back without building its own extraction. The tax form API category covers how requesting W-2 JSON from an API works and what to look for in one.

Consumer tax software is a separate route. Most people get W-2 data into a tax program through the program's own import or photo feature rather than through JSON, and the post on how to scan a W2 into tax software covers that path and what to check afterwards.

Schema Tax returns the same typed JSON from its per-page API as from the download button, so a script written against an exported file also works against the API response.

All posts in W-2 Forms