- int i, n;
- struct json_object *jtasks, *jtask, *json;
- struct task **tasks;
-
- jtasks = task_exec_json("export");
-
- if (!jtasks)
- return NULL;
-
- n = json_object_array_length(jtasks);
-
- tasks = malloc((n + 1) * sizeof(struct task *));
-
- for (i = 0; i < n; i++) {
- jtask = json_object_array_get_idx(jtasks, i);
-
- tasks[i] = malloc(sizeof(struct task));
-
- json = json_object_object_get(jtask, "id");
- tasks[i]->id = json_object_get_int(json);
-
- json = json_object_object_get(jtask, "description");
- tasks[i]->description = strdup(json_object_get_string(json));
-
- json = json_object_object_get(jtask, "status");
- tasks[i]->status = strdup(json_object_get_string(json));
-
- json = json_object_object_get(jtask, "project");
- if (json)
- tasks[i]->project
- = strdup(json_object_get_string(json));
- else
- tasks[i]->project = NULL;
-
- json = json_object_object_get(jtask, "uuid");
- tasks[i]->uuid = strdup(json_object_get_string(json));
-
- tasks[i]->note = NULL;
- }
-
- tasks[n] = NULL;
-
- json_object_put(jtasks);