Request for `--json` flag
This would help people who like:
- jq
- nushell
Thanks!
Do you have a schema in mind for the output? Just an array of the file names?
Hi. I recommend an array of objects. This allows the output to be predictable even with different command flags that change which columns are output; e.g. fd and fd -l.
Here are some examples from nushell (in reverse: telling it to generate JSON):
4 columns from ls in nu
#!/usr/bin/env nu
ls App* | to json
[
{
"name": "Applications",
"type": "dir",
"size": 194,
"modified": "2025-07-28 08:01:22.259823 -04:00"
}
]
13 columns from ls -l in nu
#!/usr/bin/env nu
ls -l App* | to json
[
{
"name": "Applications",
"type": "dir",
"target": null,
"readonly": false,
"mode": "rwxr-xr-x",
"num_links": 5,
"inode": 29820936,
"user": "person",
"group": "wizard",
"size": 194,
"created": "2023-12-20 10:26:15.718489 -05:00",
"accessed": "2025-07-30 09:04:44.061736 -04:00",
"modified": "2025-07-28 08:01:22.259823 -04:00"
}
]
1 column from fd
#!/usr/bin/env zsh
fd --json App* # proposed
Only showing one result for brevity...
[
{
"name": "Applications"
}
]
The -l option just delegates to the ls executable, fd itself doesn't generate the fields.
Ah, this makes it more interesting. 🤔
-
From one point of view, it is reasonable to expect
fdto guarantee its own output format. -
From another point of view -- like what you said (and I looked at the code) --
fddelegates to the OS-specific ls command, which is useful because it keeps the output familiar to the user.
What do you think?
I like this idea. I would definitely use a --json option if it were available.
Array of objects is not really ideal for streaming. I think json-lines / json-seq would be better.
@Cubixmeister yes, the PR now uses jsonl as output