Description
While our custom fault-tolerant .tsk format is great, we want to allow users to export their tasks into a universal JSON format so they can use their data elsewhere. We need an export <path> command.
Proposed Behavior
Typing export my_tasks.json should iterate over the current tasks and write a valid JSON array into the specified path.
Implementation Details
- Engine Method: Add
void export_to_json(const std::string &path); to task_manager.
- Lightweight Serialization: To keep the project free of heavy external dependencies, manually serialize tasks into JSON string loop using
std::ofstream and std::stringstream. The output format should look like this:
[
{
"id": 1,
"name": "Task Name",
"description": "Task Description",
"completed": false
}
]
- Command & Parser:
- Create an
export_json_command that receives the path string.
- Bind it to
parse_cli_arguments handling arguments check (requires exactly 2 arguments: export and <path>).
Acceptance Criteria
export <path> creates a valid JSON file.
- Exported JSON contains all task currently loaded in memory.
- Strings are escaped correctly.
At minimum, escape quotes, backslashes and control characters.
- File open failures are handled gracefully.
- No external JSON library is added.
Notes
- If the file cannot be opened, print error message and abort export.
- Do not modify the internal
.tsk persistence format.
- It is recommended to use a helper such as:
std::string escape_json_string(const std::string &input);
Description
While our custom fault-tolerant
.tskformat is great, we want to allow users to export their tasks into a universalJSONformat so they can use their data elsewhere. We need anexport <path>command.Proposed Behavior
Typing
export my_tasks.jsonshould iterate over the current tasks and write a valid JSON array into the specified path.Implementation Details
void export_to_json(const std::string &path);totask_manager.std::ofstreamandstd::stringstream. The output format should look like this:[ { "id": 1, "name": "Task Name", "description": "Task Description", "completed": false } ]export_json_commandthat receives the path string.parse_cli_argumentshandling arguments check (requires exactly 2 arguments:exportand<path>).Acceptance Criteria
export <path>creates a valid JSON file.At minimum, escape quotes, backslashes and control characters.
Notes
.tskpersistence format.