Skip to content

feat: implement JSON task export #4

@NotMattyS

Description

@NotMattyS

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

  1. Engine Method: Add void export_to_json(const std::string &path); to task_manager.
  2. 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
        }
    ]
  3. 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);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions