How to create an external command whose output is structured?

84 Views Asked by At

How do I write a command in another programming (e.g. JavaScript, C) that produces structured data output much like scripts written in the nu language?

I read the documentation to find out that nushell uses internal types for its own commands and that communication with external commands is done through conversion to UTF-8 string 1.

I am not satisfied with that information as I believe it should be possible to write a command that produces output in a format understood by nushell as its internal type.

1

There are 1 best solutions below

2
pmf On

If you are writing an external tool that outputs data that is going to be further processed in or with Nushell, I would recommend to still use one of the standardized formats natively understood by Nu as your intermediary protocol or exchange format. This would be reasonable because:

  • these formats can easily be converted into Nu's internal representation (the converters already exist, see the subcommands for from)
  • they are widely used, well documented, and chances are that the other language your tool is written in already provides some libraries or other means to export data using them
  • you wouldn't have to constantly monitor and then adapt your output logic to possible development changes to Nu's internal representation, as the aforementioned converters would be accordingly adapted for you by the Nu devs