---
name: dbf
displayName: dBase DBF Reader & Converter
description: Reads and converts dBase .dbf binary table files to text, CSV, or
  JSON. Use when inspecting or extracting data from legacy GIS, FoxPro, or dBase
  databases.
tags:
  - dbf
  - dbase
  - foxpro
  - extractor
  - csv
  - json
  - converter
  - gis
  - legacy
capabilities:
  - ReadDbf
  - ConvertToCsv
  - ConvertToJson
  - DumpSchema
  - InspectFields
representativeQueries:
  - read a .dbf file and show me what's inside
  - convert dbf to CSV
  - extract data from a dBase or FoxPro database file
  - what fields are in this .dbf file
  - export a DBF table to JSON
version: 0.1.0
tier: curated
---

# dBase DBF Reader & Converter

Reads dBase binary table files (.dbf) — used by legacy GIS tools (ESRI Shapefiles include a .dbf), FoxPro, Visual FoxPro, and classic dBase applications — and converts their contents to human-readable text, CSV, or JSON using the `dbfread` Python library.

## When to use

- Inspect an unfamiliar `.dbf` file to understand its field schema and record count.
- Extract the attribute table from a Shapefile or other GIS dataset.
- Convert legacy FoxPro or dBase data to CSV or JSON for downstream processing.
- Identify encoding, version, and field types before migrating data.

## Steps

1. **Verify the source file.** Confirm the file exists, is at least 32 bytes, and peek at the first byte. If the byte is unrecognised, emit a WARNING to stderr and attempt to open anyway (unknown-version files are often still readable). Exit with an error only if the file is missing, not a file, or too small.
2. **Open with dbfread.** Use `dbfread.DBF(path, encoding=None)` so the library auto-detects encoding from the language driver ID in byte 29 of the header. Fall back to `cp1252` then `latin-1` if the library raises a codec error.
3. **Inspect the schema.** Print field names, types, and lengths from `table.fields`; in text mode this happens before rows are output. In CSV and JSON modes `--schema` can be passed to dump only the field definitions and exit early.
4. **Extract and convert.** Iterate records and write to the requested output format: text summary, CSV via `csv.DictWriter`, or JSON via `json.dumps`. Serialise `datetime.date` values via `.isoformat()` and coerce any non-serialisable type to `str`.
5. **Handle edge cases.** Warn if a memo sidecar (.dbt or .fpt) is missing, skip deleted records by default, and surface rows with decoding errors rather than crashing.

## Output

- **Text summary** (default): header info (version, record count, encoding), field schema table, and the first N rows as formatted text.
- **CSV**: RFC 4180 format with a header row, all fields as strings.
- **JSON**: array of objects keyed by field name; dates as ISO-8601 strings, binary/memo as strings.

## Notes

- `scripts/dbf_convert.py` accepts `--format text|csv|json`, `--limit N` to cap row output, and `--schema` to print only the field definitions. When `--schema` and `--format` are supplied together, `--schema` takes precedence and `--format` is ignored.
- The `dbfread` library must be installed: `pip install dbfread`. The script prints an install hint and exits non-zero if the library is missing.
- Memo fields require a `.dbt` (dBase III/IV) or `.fpt` (FoxPro/Visual FoxPro) sidecar in the same directory; missing sidecars yield `None` for memo values.
- For Shapefile attribute tables, the `.dbf` is always paired with `.shp` and `.shx` — you only need the `.dbf` for tabular data.
- Numeric fields that contain only spaces represent SQL NULL; the converter preserves them as `null` (JSON) or empty string (CSV) rather than coercing to zero.

<!-- runner-fallback -->
## Remote runner (MCP)
Can't run this locally (no setup, missing dependency)? The StealthStack runner exposes the **same code** as server-side MCP tools — no local install needed: `dbf_schema`, `dbf_to_text`, `dbf_to_csv`, `dbf_to_json`. Call the `application/mcp` catalog twin of this skill (its `runnerTwin`).
