ocat JSON output now supports emitting fields which are arrays/lists

closes #542
This commit is contained in:
Jan-Piet Mens
2025-06-21 17:23:21 +02:00
parent e65fbc5067
commit 226a758076
2 changed files with 8 additions and 3 deletions

View File

@@ -516,9 +516,9 @@ Some example uses we consider useful:
* `ocat --last`
print the LAST position of all users, devices. Can be combined with `--user` and `--device`.
* `ocat ... --format csv`
produces CSV. Limit the fields you want extracted with `--fields lat,lon,cc` for example.
produces CSV. Limit the fields you want extracted with `--fields lat,lon,cc` for example. (Note: fields which are arrays or lists are not supported.)
* `ocat ... --format xml`
produces XML. Limit the fields you want extracted with `--fields lat,lon,cc` for example.
produces XML. Limit the fields you want extracted with `--fields lat,lon,cc` for example. (Note: fields which are arrays or lists are not supported.)
```xml
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='owntracks.xsl'?>
@@ -549,7 +549,7 @@ Some example uses we consider useful:
* `ocat ... --limit 10`
prints data for the current month, starting now and going backwards; only 10 locations will be printed. Generally, the `--limit` option reads the storage back to front which makes no sense in some combinations.
Specifying `--fields lat,tid,lon` will request just those JSON elements from the store. (Note that doing so with output GPX or GEOJSON could render those formats useless if, say, `lat` is missing in the list of fields.)
Specifying `--fields lat,tid,lon` will request just those JSON elements from the store. (Note that doing so with output GPX or GEOJSON could render those formats useless if, say, `lat` is missing in the list of fields. Also note, that currently fields which are arrays or lists are supported only the JSON output.)
The `--from` and `--to` options allow you to specify a UTC date and/or timestamp from which respectively until which data will be read. By default, the last 6 hours of data are produced. If `--from` is not specified, it therefore defaults to "now minus 6 hours". If `--to` is not specified it defaults to "now". Dates and times must be specified as strings, and the following formats are recognized:

5
util.c
View File

@@ -142,6 +142,11 @@ int json_copy_element_to_object(JsonNode *obj, char *key, JsonNode *node)
json_append_member(obj, key, json_mkbool(node->bool_));
else if (node->tag == JSON_NULL)
json_append_member(obj, key, json_mknull());
else if (node->tag == JSON_ARRAY) {
JsonNode *new_array = json_mkarray();
json_copy_to_object(new_array, node, false);
json_append_member(obj, key, new_array);
}
return (TRUE);
}