Add a @table formatter with optional headings#3334
Draft
yertto wants to merge 27 commits intojqlang:masterfrom
Draft
Add a @table formatter with optional headings#3334yertto wants to merge 27 commits intojqlang:masterfrom
yertto wants to merge 27 commits intojqlang:masterfrom
Conversation
8c1485a to
29b63d6
Compare
❯ echo '{"headings": ["foo", "bar", "baz"], "rows": [["a", "b", "c"], [1, null, 3]]}' | ./jq --raw-output '@table'
┌───┬────┬───┐
│foo│bar │baz│
├───┼────┼───┤
│a │b │c │
│1 │null│3 │
└───┴────┴───┘
❯ echo '[["foo", "bar", "baz"], ["a", "b", "c"], [1, null, 3]]' | ./jq --raw-output '@table'
┌───┬────┬───┐
│foo│bar │baz│
│a │b │c │
│1 │null│3 │
└───┴────┴───┘
❯ echo '{"rows": [["a", "b", "c"], [1, null, 3]]}' | ./jq --raw-output '@table'
┌─┬────┬─┐
│a│b │c│
│1│null│3│
└─┴────┴─┘
❯ ./jq --raw-output '@table' <<-EOF [ {"false":"true", "bartrue":"false", "baz":"TRUE"}, {"false":1, "bartrue":null, "baz":0}, {"false":"true false", "bartrue":"FALSE TRUE", "baz":"falsetrue"} ] EOF ┌──────────┬─────────┬──────────┐ │bartrue │baz │false │ ├──────────┼─────────┼──────────┤ │false │TRUE │true │ │null │0 │1 │ │FALSE TRUE│falsetrue│true false│ └──────────┴─────────┴──────────┘
❯ ./jq --raw-output '@table' <<-EOF [ {"false":"true", "bartrue":"false", "baz":"TRUE"}, {"false":1, "bartrue":null, "baz":0}, {"false":"true false", "bartrue":"FALSE TRUE", "baz":"falsetrue"} ] EOF ┌──────────┬──────────┬─────────┐ │false │bartrue │baz │ ├──────────┼──────────┼─────────┤ │true │false │TRUE │ │1 │null │0 │ │true false│FALSE TRUE│falsetrue│ └──────────┴──────────┴─────────┘
❯ ./jq --raw-output '@table' <<-EOF { "headings": ["baz", "bartrue"], "rows": [ {"false":"true", "bartrue":"false", "baz":"TRUE"}, {"false":1, "bartrue":null, "baz":0}, {"false":"true false", "bartrue":"FALSE TRUE", "baz":"falsetrue"} ], "color_words": ["(no|NO|false|FALSE)", "(yes|YES|true|TRUE)", "null"] } EOF ┌─────────┬──────────┐ │baz │bartrue │ ├─────────┼──────────┤ │TRUE │false │ │0 │null │ │falsetrue│FALSE TRUE│ └─────────┴──────────┘
This reverts commit 8bb9fbc.
b8429b3 to
3cc7244
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces a new
@tablestring output formatter to jq.Examples
(Nb. using
-n / --null-input,-r / --raw-output)