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

Pagination breaks about 50k characters in due to missing comma #2749

Closed
amandapouget opened this issue Jan 8, 2021 · 6 comments
Closed

Pagination breaks about 50k characters in due to missing comma #2749

amandapouget opened this issue Jan 8, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@amandapouget
Copy link

Describe the bug

gh version 1.4.0 (2020-12-15)

When getting multiple pages back, there is no comma between the pages, so the output is not JSON parseable, which makes it really difficult to work with.

Steps to reproduce the behavior

When executing a command like: gh api search/code?q=foobar --paginate, with example 571 code results (6 pages at max of 100 results per page), the output is not JSON parseable. It looks like this:
{"total_count:571, ....}{"total_count": ....}{"total_count": ....}{"total_count": ....}{"total_count": ....}{"total_count": ....}

Expected vs actual behavior

I expect to be able to grab the output to stdout coming from the process that runs gh api ... --paginate, and be able to run JSON.parse(stdout), but I can't, since the output is five objects concatinated into a string.

It would be better for --paginate to return a string of parseable JSON.

Logs

Unexpected token { at position 51235

@amandapouget amandapouget added the bug Something isn't working label Jan 8, 2021
@mislav
Copy link
Contributor

mislav commented Jan 11, 2021

Thanks for writing in! Merging all REST API responses in a single JSON document wouldn't be so hard, but it's harder when it comes to GraphQL responses where paginated collections are typically deeply nested. However, we still want to attempt to return only a single JSON document, and we're tracking it here #1268, so I will close this one as a duplicate.

As a workaround, you can parse the output of api --paginate using a JSON parser that accepts multiple concatenated JSON documents, for example the jq command-line tool.

@mislav mislav closed this as completed Jan 11, 2021
@haaami01

This comment was marked as spam.

@danielkza
Copy link

Why not at least split the documents with newlines, so it's a more manageable format for existing JSON-parsing tools?

@mislav
Copy link
Contributor

mislav commented Nov 18, 2021

@danielkza Existing JSON parser tools can either parse multiple JSON documents or they can not. The presence of a newline between the documents shouldn't be relevant or helpful to a parser.

@danielkza
Copy link

danielkza commented Nov 18, 2021

@mislav you can easily turn a parser that cannot parse multiple document into one that can by breaking lines, but you can't if there is no separator.

I would argue that "JSON lines" is a more easily handled format than "concatenated json documents", specially for shell and ad-hoc scripts.

@mislav
Copy link
Contributor

mislav commented Nov 18, 2021

@danielkza That's a good point about newlines. However, to better support JSON tools that can't part multiple documents I would rather put our efforts in #1268 than try to modify the current multi-document output to be easier for single-document parsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants