Loading JSON Into a Database Without Quote Bugs
By toolbelt maintainers ·
Updated
The name is O’Brien and your hand-built INSERT breaks. Here is how escaping actually works.
What is this tool?
Generating INSERT statements from JSON means turning objects into rows. The interesting part is not the syntax, it is the quoting.
How it works
Every object contributes its keys to one column list, so rows with different shapes still produce valid SQL. Values are converted by type and strings have their apostrophes doubled. Identifiers are double quoted.
Example
[{"id":1,"name":"O'Brien","active":true}]
becomes
INSERT INTO "users" ("id", "name", "active")
VALUES
(1, 'O''Brien', TRUE);When to use it
Seeding a development database. Moving data between systems that both speak JSON. Building a reproduction case that needs specific rows.
Optimization Tips
Keep batches in the low hundreds. Very large multi-row inserts hit server statement limits, and failing halfway is worse than several smaller runs. Quote identifiers if a column is a reserved word like order or group.
Frequently Asked Questions
Which databases accept this?
How are nulls and booleans handled?
Is this safe?
Rows with different keys?
Related tools
- CSV to JSONConvert CSV data to a JSON array of objects. Automatically maps the first row to object keys, perfect for importing spreadsheet data into web applications or APIs.
- JSON to CSVConvert a JSON array into a clean CSV file. Extract unique keys to form the header row, perfect for exporting API data for analysis in Excel or Google Sheets.
- XML to JSONConvert XML documents to JSON objects. Bridge the gap between legacy SOAP APIs and modern frontend applications while preserving attributes and hierarchical data.
- JSON to XMLConvert JSON objects to valid XML markup. Automatically handle arrays, attributes, and special characters, making it easy to integrate with older enterprise systems.