mirror of
https://github.com/simonw/datasette.git
synced 2026-10-30 15:07:43 +01:00
Row JSON now returns {"row": {...}}, closes #2612
/db/table/pk.json returns the row as an object in a "row" key instead of a single-item "rows" list. Passing any ?_shape= returns the same shapes as table JSON, so ?_shape=objects gets the previous "rows" list back. This happens in the JSON renderer, so other output renderers still get the "rows" list for row pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GaqG8H8ajwxizKXdbGrtve
This commit is contained in:
parent
e8c7b469fa
commit
28184edc52
6 changed files with 97 additions and 16 deletions
|
|
@ -153,6 +153,29 @@ Values for named SQL parameters can be provided as additional query string param
|
|||
|
||||
The response uses the same default representation described above.
|
||||
|
||||
.. _json_api_row:
|
||||
|
||||
Rows
|
||||
----
|
||||
|
||||
Every row in a table has its own JSON URL, see :ref:`RowView`. The row is returned as an object in the ``"row"`` key:
|
||||
|
||||
::
|
||||
|
||||
GET /fixtures/simple_primary_key/1.json
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"ok": true,
|
||||
"row": {
|
||||
"id": 1,
|
||||
"content": "hello"
|
||||
}
|
||||
}
|
||||
|
||||
Pass any :ref:`?_shape= option <json_api_shapes>` to return the row using the same shapes as table JSON instead. ``?_shape=objects`` returns the table default representation, with the row as the only item in the ``"rows"`` list.
|
||||
|
||||
.. _json_api_shapes:
|
||||
|
||||
Different shapes
|
||||
|
|
@ -162,7 +185,7 @@ The ``_shape`` parameter can be used to access alternative formats for the
|
|||
``rows`` key which may be more convenient for your application. There are three
|
||||
options:
|
||||
|
||||
* ``?_shape=objects`` - ``"rows"`` is a list of JSON key/value objects - the default
|
||||
* ``?_shape=objects`` - ``"rows"`` is a list of JSON key/value objects - the default for tables and queries
|
||||
* ``?_shape=arrays`` - ``"rows"`` is a list of lists, where the order of values in each list matches the order of the columns
|
||||
* ``?_shape=array`` - a JSON array of objects - effectively just the ``"rows"`` key from the default representation
|
||||
* ``?_shape=array&_nl=on`` - a newline-separated list of JSON objects
|
||||
|
|
@ -942,12 +965,10 @@ The following extras are available for row JSON responses.
|
|||
.. code-block:: json
|
||||
|
||||
{
|
||||
"rows": [
|
||||
{
|
||||
"id": 4,
|
||||
"content": "RENDER_CELL_DEMO"
|
||||
}
|
||||
],
|
||||
"row": {
|
||||
"id": 4,
|
||||
"content": "RENDER_CELL_DEMO"
|
||||
},
|
||||
"render_cell": [
|
||||
{
|
||||
"content": "<strong>Custom rendered HTML</strong>"
|
||||
|
|
|
|||
|
|
@ -29,6 +29,23 @@ The URL for executing a SQL query now looks like this:
|
|||
|
||||
**This isn't a breaking change.** API calls to the older ``/databasename?sql=...`` endpoint will redirect to the new ``databasename/-/query?sql=...`` endpoint. Upgrading to the new URL is recommended to avoid the overhead of the additional redirect.
|
||||
|
||||
(upgrade_guide_v1_row_json)=
|
||||
### Row JSON returns a single ``"row"`` object
|
||||
|
||||
The JSON for an individual row, such as ``/databasename/tablename/1.json``, previously returned that row as the only item in a ``"rows"`` list. It now returns it as an object in a ``"row"`` key:
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"row": {
|
||||
"id": 1,
|
||||
"content": "hello"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Add ``?_shape=objects`` to the URL to get a ``"rows"`` list containing that row instead, or use any other ``?_shape=`` option to get the same shapes as table JSON. See {ref}`json_api_row`.
|
||||
|
||||
(upgrade_guide_v1_metadata)=
|
||||
### Metadata changes
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue