diff options
| author | Philippe Guibert <philippe.guibert@6wind.com> | 2024-06-18 12:11:44 +0200 |
|---|---|---|
| committer | Philippe Guibert <philippe.guibert@6wind.com> | 2024-06-18 14:33:41 +0200 |
| commit | 073fec520c75d2468bd0eff0933feaab3283449c (patch) | |
| tree | ed7cfe22d3e7f60f8897462bf29d51a9ea573134 /lib/termtable.h | |
| parent | 045029e2442dbca3b6e7685438d171fa05c0f968 (diff) | |
lib: add json API to dump and override row naming convention
The following table is not compliant with caml format when displayed in
json:
> ttable_add_row(
> tt,
> "Vertex|Type|Metric|Next-Hop|Interface|Parent");
>
> ttable_json(tt, "ssdsss");
output observed:
> [..]
> {
> "Vertex":"r1",
> "Type":"",
> "Metric":0,
> "Next-Hop":"",
> "Interface":"",
> "Parent":""
> }
output expected:
> [..]
> {
> "vertex":"r1",
> "type":"",
> "metric":0,
> "nextHop":"",
> "interface":"",
> "parent":""
> }
Override the ttable_json() function with a new function which has an
extra paramter: this parameter will redefine the initial row value for
json:
> ttable_json_with_json_text(tt,
> "vertex|type|metric|nextHop|interface|parent");
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'lib/termtable.h')
| -rw-r--r-- | lib/termtable.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/termtable.h b/lib/termtable.h index 7258682bd8..0782c82abd 100644 --- a/lib/termtable.h +++ b/lib/termtable.h @@ -289,6 +289,21 @@ char *ttable_dump(struct ttable *tt, const char *newline); */ json_object *ttable_json(struct ttable *tt, const char *const formats); +/** + * Convert a table to a JSON array of objects. + * + * Caller must free the returned json_object structure. + * + * @param tt the table to convert + * @param formats an array of characters indicating what JSON type should be + * used. + * @param formats an optinal string of row headers that overrids the first row of the table. + * This is useful to get naming convention that align with caml Format. + */ +json_object *ttable_json_with_json_text(struct ttable *tt, + const char *const formats, + const char *json_override_text); + #ifdef __cplusplus } #endif |
