+static void
+table_print_json__(const struct table *table)
+{
+ struct json *json, *headings, *data;
+ size_t x, y;
+ char *s;
+
+ json = json_object_create();
+ if (table->caption) {
+ json_object_put_string(json, "caption", table->caption);
+ }
+
+ headings = json_array_create_empty();
+ for (x = 0; x < table->n_columns; x++) {
+ const struct column *column = &table->columns[x];
+ json_array_add(headings, json_string_create(column->heading));
+ }
+ json_object_put(json, "headings", headings);
+
+ data = json_array_create_empty();
+ for (y = 0; y < table->n_rows; y++) {
+ struct json *row = json_array_create_empty();
+ for (x = 0; x < table->n_columns; x++) {
+ const struct cell *cell = table_cell__(table, y, x);
+ if (cell->text) {
+ json_array_add(row, json_string_create(cell->text));
+ } else {
+ json_array_add(row, json_clone(cell->json));
+ }
+ }
+ json_array_add(data, row);
+ }
+ json_object_put(json, "data", data);
+
+ s = json_to_string(json, json_flags);
+ json_destroy(json);
+ puts(s);
+ free(s);
+}
+