mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-08 09:34:08 +02:00
Add --key option to insert/upsert/bulk for importing JSON lists nested under a top-level key
Fixes #489. JSON shaped like {"List": [...]} previously required piping through jq .List first; --key lets insert/upsert/bulk select the array directly.
This commit is contained in:
parent
74c7038b8b
commit
6a2e941863
4 changed files with 103 additions and 1 deletions
18
docs/cli.rst
18
docs/cli.rst
|
|
@ -1200,6 +1200,24 @@ You can add the ``--analyze`` option to run ``ANALYZE`` against the table after
|
|||
.. note::
|
||||
In Python: :ref:`table.insert_all() <python_api_bulk_inserts>` CLI reference: :ref:`sqlite-utils insert <cli_ref_insert>`
|
||||
|
||||
If your JSON is a single object with the list of records nested under a key, use ``--key`` to select it.
|
||||
For example, if ``dogs.json`` looks like this:
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"List": [
|
||||
{"id": 1, "name": "Cleo"},
|
||||
{"id": 2, "name": "Pancakes"}
|
||||
]
|
||||
}
|
||||
|
||||
You can import the records under the ``List`` key like so:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sqlite-utils insert dogs.db dogs dogs.json --key List
|
||||
|
||||
.. _cli_inserting_data_binary:
|
||||
|
||||
Inserting binary data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue