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

Resolves issue #1013 #1014

Closed
wants to merge 3 commits into from
Closed

Resolves issue #1013 #1014

wants to merge 3 commits into from

Conversation

abetusk
Copy link

@abetusk abetusk commented Nov 7, 2015

Added a '--fold' option to the command line. As discussed in the issue, this only affects pretty printing and numbers in a list.

A new process was created along with jv_print_extra_opt to leave the original functions untouched.

There is an unused structure variable in the jv_extra_opt for indentation that could be used later.

Testing is minimal (I tested it on a few examples, some of which appeared in #1013). I wasn't sure how to incorporate these changes in the tests that I saw.

* --fold <fold> option
* need to add tests?
added another return if element before wasn't a number ('i' index
and array counter get mismatched and array counter was reset).
@dtolnay
Copy link
Member

dtolnay commented Nov 18, 2015

Unfortunately I do not expect this to be broadly useful enough to warrant a command line flag.

If you are intending this to be used with bitmap data as in your first example, I think that is better served by this substantially simpler implementation which you could put in a library if you need it commonly:

jq <data.json -r '
    def bmp($w):
        range(0; length/$w) as $row |
        .[$row*$w : ($row+1)*$w] | join("");
    .data | bmp(32)'

If you are intending this to make JSON output with unwieldy arrays more human-readable as in your second example, I think that is better served by JSON folding provided by vim-json and similar for other editors.

Mentioning @nicowilliams in case he has a different opinion.

@nicowilliams
Copy link
Contributor

I like @dtolnay's solution. Does it work for you @abetusk?

@nicowilliams
Copy link
Contributor

@dtolnay's approach isn't easy to apply recursively all the way down without jq-coding a JSON encoder. A jq-coded JSON encoder is actually quite an interesting idea, as would be a jq-coded JSON parser.

@abetusk
Copy link
Author

abetusk commented Nov 19, 2015

OK, going to close, thanks for taking a look.

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.

None yet

3 participants