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

Option to output as json #56

Closed
jrschumacher opened this issue Jul 26, 2017 · 10 comments
Closed

Option to output as json #56

jrschumacher opened this issue Jul 26, 2017 · 10 comments

Comments

@jrschumacher
Copy link

Is there an option to output content as json rather than in an ascii table?

@germanrcuriel
Copy link
Collaborator

Hi @jrschumacher! No, there's no support for that yet sorry.

@tibu
Copy link

tibu commented Jul 28, 2017

Hi @germanrcuriel ,

I'd be happy to add JSON as output format.

What do you think about adding an option --format which could be json and later others too live csv?

@germanrcuriel
Copy link
Collaborator

@tibu Sure! It would be a nice feature!

@palashkulsh
Copy link
Owner

this has been done with
jira jql -j 1 "reporter=currentUser() and project='MMA'"

but somehow piping it to jq doesn't work with error
parse error: Unfinished JSON term at EOF at line 1565, column 4

@RichardBronosky
Copy link
Contributor

@palashkulsh I figured out the reason for the jq error. It's caused by a common issue with node cli scripts that make async network calls. If the script calls process.exit() before the output buffer is emptied, pipes get closed (usually at 64k). You can compare these 2 commands:

$ jira jql -j 1 "reporter=currentUser()" > /tmp/1.json
$ jira jql -j 1 "reporter=currentUser()" | cat > /tmp/2.json
$ ls -lh /tmp/[12].json
-rw-r--r--  1 bruno  wheel   240K Jul 12 01:44 /tmp/1.json
-rw-r--r--  1 bruno  wheel    64K Jul 12 01:45 /tmp/2.json

as a result, you can jq . < /tmp/1.json but not jq . < /tmp/2.json

commenting out line 37 in bin/jira.js resolves this. Afterward you can do a simple:

$ jira jql -j 1 "reporter=currentUser()" | jq . | head -n4
[
  {
    "expand": "operations,customfield_10028.properties,versionedRepresentations,editmeta,changelog,customfield_10029.properties,customfield_10047.properties,renderedFields",
    "id": "13490",

@palashkulsh palashkulsh self-assigned this Jul 12, 2019
@palashkulsh
Copy link
Owner

Awesome !! thanks @RichardBronosky it works. Before pushing this change I am thinking what would be the downside of not doing process.exit(0) . any thought?

@palashkulsh palashkulsh reopened this Jul 12, 2019
@RichardBronosky
Copy link
Contributor

I'm not sure about downsides. Based on nodejs/node#3669 (comment) and nodejs/node#2972 (comment) (both comments by the same user, mind you) seems like the downsides are on using it.

I'm looking into nodejs/node#6456 to see what other option there is.

Also, I have a PR coming that adds the option to get json output from the ls command.

@palashkulsh
Copy link
Owner

palashkulsh commented Jul 12, 2019

will be removing the exit part.
Also just fyi you can jira jql ALIAS functionality to have jira ls on steroids.

palashkulsh added a commit that referenced this issue Jul 12, 2019
fixes #56 as process.exit does not wait for stdout
RichardBronosky added a commit to RichardBronosky/jira-cmd that referenced this issue Jul 12, 2019
`jira ls --help` will show that `jira ls -j 1` works just like `jira jql -j1 '...'`
@RichardBronosky
Copy link
Contributor

My PR https://github.com/germanrcuriel/jira-cmd/pull/89 uses the nodejs/node#6456 method instead of the change you made (at my indication) in https://github.com/germanrcuriel/jira-cmd/pull/88 I don't care which way you address the buffer issue. I can modify my branch if you want to keep your change. Just let me know.

@palashkulsh
Copy link
Owner

Surething @RichardBronosky , will let you know. Due to some time crunch for next 4-5 hours, will test post that.

palashkulsh pushed a commit that referenced this issue Jul 12, 2019
`jira ls --help` will show that `jira ls -j 1` works just like `jira jql -j1 '...'`
palashkulsh pushed a commit that referenced this issue Mar 19, 2020
`jira ls --help` will show that `jira ls -j 1` works just like `jira jql -j1 '...'`
germanrcuriel pushed a commit that referenced this issue Mar 30, 2020
`jira ls --help` will show that `jira ls -j 1` works just like `jira jql -j1 '...'`
germanrcuriel pushed a commit that referenced this issue Mar 30, 2020
`jira ls --help` will show that `jira ls -j 1` works just like `jira jql -j1 '...'`
germanrcuriel pushed a commit that referenced this issue Mar 30, 2020
fixes #56 as process.exit does not wait for stdout
germanrcuriel pushed a commit that referenced this issue Mar 30, 2020
`jira ls --help` will show that `jira ls -j 1` works just like `jira jql -j1 '...'`
germanrcuriel pushed a commit that referenced this issue Mar 30, 2020
`jira ls --help` will show that `jira ls -j 1` works just like `jira jql -j1 '...'`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants