Skip to content
toolbelt
Back to Guides

Getting Data Out of a Dump File

By ·

Updated

The only copy of your data is INSERT statements. Here is how to read them back into something you can work with.

What is this tool?

A SQL dump stores rows as INSERT statements. Converting to JSON means turning those value tuples back into objects.

How it works

I find the column list and the tuples, then walk the tuple body tracking quote state and bracket depth, so a comma inside a string does not split a column. Doubled single quotes — the SQL escape for an apostrophe — are turned back into one.

Example

INSERT INTO users (id, name) VALUES (1, 'Ada'), (2, 'O''Brien');

becomes

[{"id":1,"name":"Ada"},{"id":2,"name":"O'Brien"}]

When to use it

Recovering data when no export tool exists. Turning a fixture written as SQL into JSON your tests can read. Checking what a migration actually inserted.

Optimization Tips

Dates will arrive as strings, because that is how SQL dumps quote them. Convert them deliberately rather than assuming the type survived. And convert one table at a time — the tool reads one statement.

Frequently Asked Questions

Are escaped quotes handled?
Yes. A doubled single quote becomes a single apostrophe.
Why are dates strings?
SQL writes dates quoted, so they are text in the dump. Parse them yourself.
Does it run against a database?
Never. It is text parsing.
Multiple statements?
Run it once per statement.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools