Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -i to indent JSON output #4

Merged
merged 1 commit into from
May 6, 2019
Merged

Conversation

leahneukirchen
Copy link
Contributor

This is very easy to add, and quite useful.

@sclevine sclevine merged commit 4c81e97 into sclevine:master May 6, 2019
sclevine added a commit that referenced this pull request May 6, 2019
sclevine added a commit that referenced this pull request May 6, 2019
@sclevine
Copy link
Owner

sclevine commented May 6, 2019

Thanks for the contribution!

I also applied your new -i flag to TOML output in 885adeb, as TOML has a concept of indentation as well. The indents applied by the TOML parser package are more aggressive than the official TOML spec examples, so this is a good opportunity to disable them by default.

If you're okay with the additional changes, I'll cut a v4.0.0 release this week. (The TOML output change is technically backwards-incompatible, hence the major version bump.)

@leahneukirchen
Copy link
Contributor Author

Sounds useful, thanks.

@Alhadis
Copy link

Alhadis commented Jul 26, 2020

You should have indented with tabs, because:

  • It's easier to convert them to spaces than vice-versa,
  • Raw tabs are illegal in JSON strings, so piping through sed -e 's/\t/    /g' or expand -t4 won't mutilate JSON data,
  • They're better than spaces. No, seriously, it's scientifically-proven. Fight me.

@sclevine
Copy link
Owner

I wouldn't want to deprive anyone of an income!

In all seriousness, I'm definitely in the "tabs for indentation, spaces for alignment" camp, which is same philosophy the Go authors appear to have.

jq defaults to spaces. Regardless of my personal tastes, I'd like to copy jq's defaults, given that yj is commonly used as a preprocessor for input into jq. I'd consider making this configurable, but I'm not sure if the complexity is warranted (especially given that you could just yj | jq --tab).

@Alhadis
Copy link

Alhadis commented Jul 27, 2020

In all seriousness, I'm definitely in the "tabs for indentation, spaces for alignment" camp

Yup, same. But here it's a simple matter of practicality: I'd say that jq is making a mistake as well...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants