I'm trying to import some data into a PostgreSQL database. The data is stored in a JSON file (file.json) that looks like this:
[
{
"key1": 12,
"key2": 2
},
{
"key1": 151,
"key2": 9
}
]
I'm using psql and the instructions are listed here. The table that JSON data will be imported in is created:
create table table_import (doc json);
While copying data into the table
\copy table_import from '/location/file.json'
I get the following error:
ERROR: invalid input syntax for type json
DETAIL: Token "" is invalid.
CONTEXT: JSON data, line 1: ...
COPY table_import, line 1, column doc: "["
Since I'm doing exactly what the instructions in the answer are, I'm starting a new thread.
jq -c '.[]' <file>.json > <new-file>.json(the-ccreates a compact format without line breaks). Then you can import the<new-file>.json