ODS to JSON — an application expecting objects meeting a spreadsheet supplying a grid
The app wants objects; the spreadsheet has a grid. The conversion takes the first row of the OpenDocument sheet as keys and writes one object per following row. The interesting part is not the mapping but what the receiving code has to tolerate afterwards: strings where you expected numbers, null where you expected a value, and extra objects from sheets nobody asked for.
Cell formatting, colours, column widths and merged ranges are dropped; only stored values survive.
Processed on your device. Files aren’t sent anywhere.
Grid to objects
The reader opens the compressed OpenDocument container, reads the sheet as displayed text, and maps columns onto property names.
- The first row supplies the keys.
- A blank header cell gets a generated name such as column_3.
- Repeated header names get numeric suffixes.
- Rows that are entirely empty produce no object.
What the receiving code must tolerate
Cells are read as the text the sheet displays, so nothing arrives typed. Validate before trusting.
| Cell | JSON value | Tolerate |
|---|---|---|
| Fee of 40 | "40" | a string, not a number |
| Empty fee cell | null | handle explicitly, not as zero |
| Date shown as 12 Mar 2003 | "12 Mar 2003" | parse or keep as text |
| Text with an accent | the same characters | UTF-8 output |
Extra sheets appended into one array
With All sheets every sheet in the document is converted and appended into one array. Nothing marks which sheet an object came from, so a Notes sheet contributes objects with keys your schema never declared. Use First sheet unless you genuinely want every sheet.
Questions
Why is a fee a string?
What does a blank cell become?
Are OpenDocument formulas evaluated?
Do other sheets appear in the array?
Dates as displayed text
A date cell leaves as the characters shown on screen, not as an ISO timestamp and not as a serial number. The document's own formatting decides the shape, so two files can produce two different date strings for the same day.
Validating the JSON before shipping it
Treat the output as an untrusted payload.
- Convert the .ods file and download the JSON.
- Parse it and list the keys you actually received.
- Assert the types your schema expects and coerce where needed.
- Count objects against the sheet rows.
- Decide whether extra sheets were wanted before you ship.