diff --git a/datasette/renderer.py b/datasette/renderer.py index acf23e59..182d4c0c 100644 --- a/datasette/renderer.py +++ b/datasette/renderer.py @@ -11,13 +11,13 @@ from datasette.utils.asgi import Response def convert_specific_columns_to_json(rows, columns, json_cols): json_cols = set(json_cols) - if not json_cols.intersection(columns): + if not json_cols.intersection(columns) and not json_cols == {"*"}: return rows new_rows = [] for row in rows: new_row = [] for value, column in zip(row, columns): - if column in json_cols: + if column in json_cols or (json_cols == {"*"}): try: value = json.loads(value) except (TypeError, ValueError): diff --git a/docs/json_api.rst b/docs/json_api.rst index 65031bf4..e498f58e 100644 --- a/docs/json_api.rst +++ b/docs/json_api.rst @@ -207,6 +207,12 @@ query string arguments: JSON. Without this argument those columns will be returned as JSON objects that have been double-encoded into a JSON string value. + If you have many columns containing JSON values, you can pass ``_json=*`` + to attempt converting loading all columns as JSON. This is a best effort + approach. Any columns that fail to render as valid JSON will be passed + through unaltered, while any column with valid JSON will be converted. + There may be a performance impact on large result sets. + Compare `this query without the argument `_ to `this query using the argument `_ ``?_json_infinity=on``