Add columns support to JSON loader for selective key filtering
NONE
I need this feature right now. It would be great if it could automatically fill in None for non-existent keys instead of reporting an error.
2025-07-03T06:52:10Z
https://github.com/huggingface/datasets/pull/7652#issuecomment-3031087320
https://api.github.com/repos/huggingface/datasets/issues/7652
IC_kwDODunzps60qrjY
https://api.github.com/repos/huggingface/datasets/issues/comments/3031087320/reactions
2025-07-03T06:52:10Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3031087320
https://avatars.githubusercontent.com/u/51043929?v=4
https://api.github.com/users/aihao2000/events{/privacy}
https://api.github.com/users/aihao2000/followers
https://api.github.com/users/aihao2000/following{/other_user}
https://api.github.com/users/aihao2000/gists{/gist_id}
https://github.com/aihao2000
aihao2000
MDQ6VXNlcjUxMDQzOTI5
https://api.github.com/users/aihao2000/orgs
https://api.github.com/users/aihao2000/received_events
https://api.github.com/users/aihao2000/repos
https://api.github.com/users/aihao2000/starred{/owner}{/repo}
https://api.github.com/users/aihao2000/subscriptions
User
https://api.github.com/users/aihao2000
public
CONTRIBUTOR
> I need this feature right now. It would be great if it could automatically fill in None for non-existent keys instead of reporting an error.

Hi @aihao2000, Just to confirm — I have done the changes you asked for!
If you pass columns=["key1", "key2", "optional_key"] to load_dataset(..., columns=...), and any of those keys are missing from the input JSON objects, the loader will automatically fill those columns with None values, instead of raising an error.
2025-07-03T09:52:48Z
https://github.com/huggingface/datasets/pull/7652#issuecomment-3031633365
https://api.github.com/repos/huggingface/datasets/issues/7652
IC_kwDODunzps60sw3V
https://api.github.com/repos/huggingface/datasets/issues/comments/3031633365/reactions
2025-07-03T09:52:48Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3031633365
https://avatars.githubusercontent.com/u/142811259?v=4
https://api.github.com/users/ArjunJagdale/events{/privacy}
https://api.github.com/users/ArjunJagdale/followers
https://api.github.com/users/ArjunJagdale/following{/other_user}
https://api.github.com/users/ArjunJagdale/gists{/gist_id}
https://github.com/ArjunJagdale
ArjunJagdale
U_kgDOCIMgew
https://api.github.com/users/ArjunJagdale/orgs
https://api.github.com/users/ArjunJagdale/received_events
https://api.github.com/users/ArjunJagdale/repos
https://api.github.com/users/ArjunJagdale/starred{/owner}{/repo}
https://api.github.com/users/ArjunJagdale/subscriptions
User
https://api.github.com/users/ArjunJagdale
public
CONTRIBUTOR
Hi! any update on this PR?
2025-07-14T10:41:53Z
https://github.com/huggingface/datasets/pull/7652#issuecomment-3068910341
https://api.github.com/repos/huggingface/datasets/issues/7652
IC_kwDODunzps6269sF
https://api.github.com/repos/huggingface/datasets/issues/comments/3068910341/reactions
2025-07-14T10:41:53Z
https://api.github.com/repos/huggingface/datasets/issues/comments/3068910341
https://avatars.githubusercontent.com/u/142811259?v=4
https://api.github.com/users/ArjunJagdale/events{/privacy}
https://api.github.com/users/ArjunJagdale/followers
https://api.github.com/users/ArjunJagdale/following{/other_user}
https://api.github.com/users/ArjunJagdale/gists{/gist_id}
https://github.com/ArjunJagdale
ArjunJagdale
U_kgDOCIMgew
https://api.github.com/users/ArjunJagdale/orgs
https://api.github.com/users/ArjunJagdale/received_events
https://api.github.com/users/ArjunJagdale/repos
https://api.github.com/users/ArjunJagdale/starred{/owner}{/repo}
https://api.github.com/users/ArjunJagdale/subscriptions
User
https://api.github.com/users/ArjunJagdale
public
Fixes #7594 
This PR adds support for filtering specific columns when loading datasets from .json or .jsonl files — similar to how the columns=... argument works for Parquet.

As suggested, support for the `columns=...` argument (previously available for Parquet) has now been extended to **JSON and JSONL** loading via `load_dataset(...)`. You can now load only specific keys/columns and skip the rest — which should help in cases where some fields are unclean, inconsistent, or just unnecessary.

### Example:

```python
from datasets import load_dataset

dataset = load_dataset("json", data_files="your_data.jsonl", columns=["id", "title"])
print(dataset["train"].column_names)
# Output: ['id', 'title']
```

### Summary of changes:

* Added `columns: Optional[List[str]]` to `JsonConfig`
* Updated `_generate_tables()` to filter selected columns
* Forwarded `columns` argument from `load_dataset()` to the config
* Added test for validation(should be fine!)

Let me know if you'd like the same to be added for CSV or others as a follow-up — happy to help.