Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion docs/output_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,63 @@ We have introduced a new `--format` option to provide a unified way to specify t
It accepts the following values:
* `csv`: Display output as comma-separated values.
* `table`: Display output as a formatted table (default).
* `json`: Display output as JSON (to be fully implemented in future updates).
* `json`: Display output as JSON.

Example:
```sh
kaggle competitions list --format csv
kaggle competitions list --format table
kaggle competitions list --format json
```

For most commands, the JSON output is a list of objects representing the rows, with keys corresponding to the column headers. For detailed commands like `topics show`, it returns a structured object:
```json
{
"topic": { ... },
"comments": [ ... ]
}
```

### Projections (Field Selection)

The `--format` option supports optional `gcloud`-style field selection (projections) by appending a comma-separated list of fields in parentheses to the format name. This allows you to limit the output to only the specified fields and control their order.

Projections are supported for all formats (`csv`, `table`, `json`).

Example:
```sh
# Only show 'ref' and 'reward' columns for competitions in a table
kaggle competitions list --format "table(ref,reward)"

# Export only 'id' and 'publicScore' to JSON for team submissions
kaggle competitions team-submissions --format "json(id,publicScore)" <team_id>

# Export only 'name' and 'size' to CSV for dataset files
kaggle datasets files -d zillow/zecon --format "csv(name,size)"
```

You can specify fields using either their field names (e.g. `totalBytes`) or their display labels (e.g. `size`). If a field is not recognized, the CLI will display an error listing the allowed fields.

#### Special Case: Topics Show

For `topics show` commands, which output both a parent topic and a list of comments, the projection is applied to both types of objects. Fields matching the topic are applied to the topic output, and fields matching comments are applied to the comment output.

Example:
```sh
kaggle forums topics show 123 --format "json(title,content)"
```
In this case, `title` (which is a topic field) will be preserved in the topic output, and `content` (which is a comment field) will be preserved in the comments output.
```json
{
"topic": {
"title": "Test Title"
},
"comments": [
{
"content": "Comment Content"
}
]
}
```

### Mutual Exclusion
Expand Down
Loading
Loading