Skip to content

save: structured data to .txt / unknown extensions should default-serialize or give an actionable error #18700

Description

@AMDphreak

Describe the solution you'd like

When save gets structured pipeline data (tables/records) and the destination extension does not map to a to <format> serializer (e.g. .txt, no extension, or an unknown suffix), Nushell should not hard-fail with only Can't convert to string.

Prefer one of:

  1. Default serialize structured input to a stable text format (json or nuon) and write it, ideally with a short stderr hint: note: no serializer for .txt; wrote JSON. Extension still overrides when known (.csvto csv, etc.).
  2. Or, if defaulting is too magical: keep the error but make it actionable — mention | to json | save … and | table | ansi strip | save … in the message.

Either way: people should not be forced to rename a file to *.json just to dump structured data. Filenames are hints; content is the point.

Describe alternatives you've considered

  • Status quo + docs (ls | to json | save out.txt, ls | table | ansi strip | save out.txt) — works, still a paper cut.
  • Always treat .txt as table render — matches the screen, but embeds ANSI unless stripped; bad for a data dump.
  • Remove all extension-based auto-to (explicit only) — consistent, but regresses the nice save foo.json path.

Additional context

Related / prior:

This is the other side of that coin: known extensions are helpful; unknown ones become a brick wall.

Interactive ls looks like text because the REPL pipes through table. Internal values are not JSON; .json triggers convert-then-write via to json. The asymmetry (output.json works, output.txt fails) is what feels overly strict.

ls | save -f output.txt   # fails: can't convert record<…> to string
ls | save -f output.json  # works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions