How to Export DB2 to JSON, Step by Step
Step 1: Connect to DB2
Host, port (50000 by default for LUW), database and account, then connect. The Test button reports the server version before anything is read.
Step 2: Choose the table or the query
A single table, every table in a schema, or a SELECT pasted in - the column list comes from what you pick and stays editable.
Key Features
DB2 exports are usually batch jobs, so the useful features are the ones that survive a schedule:
- Table, query, or a whole schema - a batch run writes one file per table, named after the table.
- Dated file names (
orders_#yyyy#-#mm#-#dd#) so a nightly run does not overwrite yesterday. - The format settings are saved with the task instead of re-chosen each time.
- Types are honoured:
DECIMALkeeps its scale,TIMESTAMPits date,CLOBis not cut. - Saved and scheduled: Task Scheduler,
cronorlaunchd. - Local: the file is written where you are, and the DB2 password never leaves the machine.
What a DB2 column becomes in the JSON
A JSON is text, so the interesting part is where each DB2 type loses something on the way out:
| In DB2 | In the JSON |
|---|---|
| INTEGER, BIGINT | a JSON number - beyond 2^53 a JavaScript parser rounds it |
| DECIMAL(p,s) | a JSON number with the declared scale |
| CHAR, VARCHAR | a JSON string, escaped |
| CLOB, DBCLOB | a JSON string - the text, escaped |
| XML | its serialised text inside a string - the structure is not reshaped into members |
| DATE, TIMESTAMP | a string - JSON has no date type |
| NULL | the JSON literal null |
| BLOB, FOR BIT DATA | not text - export HEX(col) or the document is invalid |
One array, one object per line, or SQL/JSON in the query?
DB2 can build JSON inside a query with JSON_OBJECT and JSON_ARRAY (and JSON_AGG in newer releases). That is the right tool when the document shape is a report; it is not a file writer - the result is one value that has to be fetched in one piece.
On z/OS the utility for getting rows out is called UNLOAD, and it writes delimited files, not JSON - unload data from DB2 in JSON form is exactly the gap this page fills.
Two shapes are what consumers ask for: one array of objects for an API, and one object per line - JSONL/NDJSON - which appends and streams. Both are a setting here, on the same connection that reads the table.
DB2 to JSON — Quick Facts
- Database
- DB2 for LUW 9.x-12.x, and z/OS through the same connection
- Default port
- 50000 (LUW)
- Identifier quoting
- "double quotes"; unquoted names fold to UPPERCASE
- Shapes
- one array of objects, or one object per line (JSONL/NDJSON)
- Numbers
- BIGINT beyond 2^53 and DECIMAL are at risk in float parsers
- Dates
- strings - JSON has no date type
- XML columns
- carried as text, not re-structured
- SQL-side alternative
JSON_OBJECT/JSON_ARRAY, built as one value
Common pitfalls when exporting DB2 to JSON
- A DB2
XMLcolumn arrives as a string: a consumer expecting a nested object has to parse it. - DECIMAL values written as numbers lose their scale in a float parser - if the scale matters, keep them as strings.
- A CLOB holding JSON is exported as a string, so the consumer sees double-encoded JSON.
- One huge array cannot be streamed; JSONL can, and it appends across runs.
- Unquoted identifiers fold to UPPERCASE, so JSON keys come out as
"DEPT_ID"unless the mapping renames them.
Which searches land here
This page exports DB2 → JSON. The neighbouring searches below want another format or another direction:
| What you searched | Meaning | Page |
|---|---|---|
| db2 to json, db2 export to json, db2 query to json | read DB2, write a JSON file | this page |
| db2 to jsonl, db2 to json array, ndjson export | one object per line, or one array - both are settings on this page | this page |
| db2 to csv, db2 to txt, db2 to tsv, db2 to xml, db2 to sql, db2 to html, db2 to excel | a different output format from the same connection | CSV / TXT / TSV / XML / SQL / HTML / Excel |
| csv to db2, import csv into db2 | the reverse direction - a file into DB2 | CSV to DB2 |
| db2 export command, db2look, db2move | the server-side commands: EXPORT writes on the DB2 host, db2look is DDL, db2move moves a database | this page (client export) or the DB2 manual |
| csv to dbf converter, dbf to csv | a different pair entirely (DBF, not DB2) - the names are one letter apart | CSV to DBF / DBF to CSV |
One letter separates DB2 from DBF, and both appear in the same keyword space: the columns are different formats, not different vendors.
Verify three things before you hand the file over
- Row count: compare
SELECT COUNT(*)with the rows the task reports - a short count means a rejected row. - One
DECIMALand oneTIMESTAMP: the scale should be intact and the timestamp should not have lost its date. - One long
CLOBand one accented string: the text should be complete and readable in the target application.
Frequently Asked Questions
Download Withdata DBToFile Now
Start exporting DB2 to JSON in seconds - free trial for all platforms.
$75 one-time · volume discounts to $55 · 30-day money-back · pricing & licence terms

