MariaDB to JSON: Tables and Query Results

One JSON document per table, or one object per row - with real types kept, so a number stays a number and NULL stays null.

Download DBToFile — free trial

Version 3.1.2 · Windows, Linux, macOS · 30-day free trial, then $75 one-time · runs fully offline

DBToFile: MariaDB to JSON target - document shape, indentation and NULL handling

How to Export MariaDB to JSON, Step by Step

Step 1: Connect to MariaDB

Host, port (3306 by default), account and database, then connect. The Test button reports the server version, so a grant or firewall problem shows up before the export.

Step 1 screenshot

Step 2: Choose the table or the query

A single table, every table in a schema, or a SELECT pasted straight in - the column list comes from what you pick and stays editable.

Step 2 screenshot

Step 3: Set the JSON shape

Delimiter, quoting, header row, NULL marker, encoding and the file name - set once and saved with the task. Dynamic file name covers the dated-file case the old export-...-with-current-date posts described.

Step 3 screenshot

Step 4: Run and check the file

The task window reports the row count at the end; open the file and compare the first and last row before anything else consumes it.

Step 4 screenshot

Key Features

DBToFile connects to MariaDB the way any client does, so nothing has to be installed or granted on the server side - and every export is a saved task rather than a set of options you rebuild each time:

  • Table, query, or every table in a schema - a batch run writes one file per table, named after the table.
  • Column list and order are part of the task, so the output does not drift when the table grows.
  • Types are honoured while writing: dates stay dates, numbers are not quoted, NULL keeps its own marker.
  • The file is written where you are, not on the database host - no secure_file_priv path to chase.
  • Saved and scheduled: the same task runs from Task Scheduler, cron or launchd.
  • Local: the rows travel between your machine and the database, nowhere else.

What a MariaDB column becomes in the JSON

A JSON is text, so the interesting part is where each MariaDB type loses something on the way out.

In MariaDBIn the JSON
INT, BIGINT, DECIMALa JSON number - watch BIGINT UNSIGNED beyond 2^53 and DECIMAL read by a float parser
VARCHAR, TEXTa JSON string, escaped
DATETIME, TIMESTAMPa string in ISO form; JSON has no date type
DATEa string
NULLthe JSON literal null - the one format where NULL is not lost
JSON columnkept as nested JSON when the document shape allows it, otherwise as a string
BLOB, VARBINARYnot text - export HEX(col) or the tool writes the raw bytes into the string
ENUM / SETthe label

One array, one object per line, or JSON_OBJECT() in SQL?

Two shapes live behind this one page: one array holding every row as an object (what a web API expects), or one object per line - JSONL/NDJSON, which appends and streams. The choice is a setting, not a different tool, and it is the only real decision in a JSON export.

MariaDB can also build JSON in SQL with JSON_OBJECT() and JSON_ARRAYAGG(), and that is the right tool for a report. What it does not give you is a file: the aggregate is limited by max_allowed_packet and the result still has to be fetched. A client export streams instead.

MariaDB to JSON — Quick Facts

Shape
array of objects, or one object per row (JSONL)
Numbers
BIGINT beyond 2^53 and DECIMAL lose precision in float parsers
Dates
strings - JSON has no date type
NULL
the literal null
Default port
3306
Server-side alternative
JSON_OBJECT / JSON_ARRAYAGG, limited by max_allowed_packet

Common pitfalls when exporting MariaDB to JSON

  • A JSON column exported as a string arrives double-encoded: "{\"a\":1}" instead of an object.
  • BIGINT ids beyond 2^53 change value when a JavaScript or Python float parser reads the file.
  • TIMESTAMP written in the session zone looks like a different instant to a reader that assumes UTC.
  • One huge array is not streamable: a consumer has to parse the whole file before it sees the first row - JSONL avoids that.
  • Invalid UTF-8 in a TEXT column makes the document unparseable; the writer has to know the client charset.

Which searches land here

This page exports MariaDB → JSON. The neighbouring searches below mean a different direction, a different format or a different target engine:

What you searchedMeaningPage
mariadb export to json, export table to json, mariadb export jsonread MariaDB, write a JSON filethis page
json to mariadb, import json into mariadbthe reverseJSON to MariaDB
mariadb to csv, mariadb to tsv, mariadb to txt, mariadb to xml, mariadb to sql, mariadb to htmla different output format from the same connectionCSV / TSV / TXT / XML / SQL / HTML
mariadb to sqlite, mariadb to sql server, mariadb to mysqlanother database engine as the target, not a fileMariaDB to SQLite / SQL Server / MySQL
mariadb export database to sql file, mysqldump single tablea script of rows, or a schema dumpthis page (MariaDB to SQL)

The export itself is the same job in both directions - it is the reader and the target system that decide which side of the arrow a query belongs to.

Verify three things before you hand the file over

  • Row count: compare SELECT COUNT(*) with the records the task reports - a short count means a skipped or rejected row.
  • First and last row: check the header and the very last field, which is where a quoting or newline problem shows up first.
  • Types in the file: a date should not be quoted as text, a number should not carry a thousands separator.

Frequently Asked Questions

How do I export MariaDB to JSON?
Connect, choose the table or query, pick the document shape (array or one object per row), then write the file.
Array or one object per line?
An array is what web APIs expect; one object per line (JSONL) streams and can be appended, which is better for logs and big tables.
Are the types preserved?
Numbers and nulls yes; dates become strings because JSON has no date type.
Why is my JSON column double-encoded?
It was exported as text. Keep it nested (when the shape allows) or parse the string on the receiving side.
Can I export only some columns?
Yes - the column list is part of the task, so a query or a selected subset both work.

Download Withdata DBToFile Now

Start exporting MariaDB to JSON in seconds - free trial for all platforms.

$75 one-time · volume discounts to $55 · 30-day money-back · pricing & licence terms

Download Free Trial