TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: JSON Output for CLI Tools?

3 点作者 zeisss将近 5 年前
I am currently our public command-line tool some love and although we officially have an `--output=json` flag, it rarely works or does anything useful.<p>* While thinking about how to fix&#x2F;implement this for more commands I was wondering if this kind of more structured output is actually of interest&#x2F;use for developers&#x2F;devops&#x2F;SRE?<p>Some context: The tool in question is a client for our API and used for validation + updating resources and triggering long running loadtest jobs. Users are developers, although we also recommend it for integration into CI&#x2F;CD pipelines etc.<p>Any feedback is welcome :)

3 条评论

mikece将近 5 年前
If the idea is to have output from CLI apps&#x2F;scripts that can be easily parsed so that chaining scripts together without regexing yourself to death is the goal this sounds like what PowerShell Core (which runs on macOS and Linux as well) does: PS commands return objects -- with a default .ToString() output if you don&#x27;t grab the result and use it in the next step&#x2F;script -- allowing easy object.property accessors as well as foreach iteration if the command returns a list&#x2F;array of objects.
评论 #24081467 未加载
maerF0x0将近 5 年前
I find json output massively valuable because I combine it with `jq` instead of having to try and cut (or other command) slice up responses.
viraptor将近 5 年前
If your json-vs-text output drifts often, you could make the backing objects the same. AWS kind of does it in their cli tool. It&#x27;s all objects and json inside, but you see nicely rendered tables. &quot;--output=json&quot; gives you the real&#x2F;raw data.