home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 1112734577

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/datasette/issues/1729#issuecomment-1112734577 https://api.github.com/repos/simonw/datasette/issues/1729 1112734577 IC_kwDOBm6k_c5CUvtx 9599 2022-04-28T23:08:42Z 2022-04-28T23:08:42Z OWNER

That prototype is a very small amount of code so far: ```diff diff --git a/datasette/renderer.py b/datasette/renderer.py index 4508949..b600e1b 100644 --- a/datasette/renderer.py +++ b/datasette/renderer.py @@ -28,6 +28,10 @@ def convert_specific_columns_to_json(rows, columns, json_cols):

def json_renderer(args, data, view_name): """Render a response as JSON""" + from pprint import pprint + + pprint(data) + status_code = 200

 # Handle the _json= parameter which may modify data["rows"]

@@ -43,6 +47,41 @@ def json_renderer(args, data, view_name): if "rows" in data and not value_as_boolean(args.get("_json_infinity", "0")): data["rows"] = [remove_infinites(row) for row in data["rows"]]

  • Start building the default JSON here

  • columns = data["columns"]
  • next_url = data.get("next_url")
  • output = {
  • "rows": [dict(zip(columns, row)) for row in data["rows"]],
  • "next": data["next"],
  • "next_url": next_url,
  • } +
  • extras = set(args.getlist("_extra")) +
  • extras_map = {
  • _extra= : data[field]

  • "count": "filtered_table_rows_count",
  • "facet_results": "facet_results",
  • "suggested_facets": "suggested_facets",
  • "columns": "columns",
  • "primary_keys": "primary_keys",
  • "query_ms": "query_ms",
  • "query": "query",
  • }
  • for extra_key, data_key in extras_map.items():
  • if extra_key in extras:
  • output[extra_key] = data[data_key] +
  • body = json.dumps(output, cls=CustomJSONEncoder)
  • content_type = "application/json; charset=utf-8"
  • headers = {}
  • if next_url:
  • headers["link"] = f'<{next_url}>; rel="next"'
  • return Response(
  • body, status=status_code, headers=headers, content_type=content_type
  • ) + + # Deal with the _shape option shape = args.get("_shape", "arrays") # if there's an error, ignore the shape entirely ```
{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
1219385669  
Powered by Datasette · Queries took 1.616ms · About: github-to-sqlite