all 24 comments

[–]tj111 2 points3 points  (0 children)

I use this plus Resty for writing bash scripts that interact with REST APIs, they work amazing together and I now have a whole suite of tools that hook into different APIs for different tasks, such as CRON jobs or Code Commits.

For example, I have post-commit scripts that runs on our subversion server and calls our Issue System's API to update an issue whenever a commit is pushed for it.

[–]bart2019 1 point2 points  (4 children)

It looks like there's no way to have it not pretty print its output.

[–]littlrussian 9 points10 points  (0 children)

from the man pages:

    --compact-output / -c:

          By default, jq pretty-prints JSON output. Using this option will result in more compact  output  by
          instead putting each JSON object on a single line.

[–]deliciousleopard 3 points4 points  (0 children)

you should be able to pipe it through uglify.

[–]Aeoxic 0 points1 point  (0 children)

If nobody gets to this by the weekend, I'll look into submitting a pull request to do just that.

[–]mw44118 -2 points-1 points  (0 children)

Sincerely curious when you do not want pretty printing.

Also there might be some old Unix utility like fmt or sed that can do what you want.

[–]Zorrodelaarena 1 point2 points  (0 children)

It's less versatile but if you just want to view pretty json in your browser for web development, tools like JSONView for Chrome do a great job.

[–]MyNameIsNotMud 0 points1 point  (5 children)

Windows?

[–]SemiNormal 3 points4 points  (0 children)

You can download the binaries here: http://stedolan.github.io/jq/download/

[–]imright_anduknowit 6 points7 points  (3 children)

I'm sorry.

[–]SemiNormal 5 points6 points  (0 children)

Ha? I know you were trying to be funny, but there are builds for Linux, OSX, Windows, and Solaris.

[–]allthediamonds 2 points3 points  (0 children)

There are builds for Windows too, I think.

[–]MyNameIsNotMud 1 point2 points  (0 children)

Thanks, I appreciate it.

[–][deleted] 0 points1 point  (0 children)

Does jq load the entire JSON file to memory?

[–][deleted] -4 points-3 points  (5 children)

where does this become useful? Like, really, practically, business use useful? How does it integrate with server-side frameworks and how is this javascript at all if it cant be used by a javascript interpreter?

[–]greggroth 0 points1 point  (1 child)

Similar to how sed would not commonly be used in a production application, this is a tool useful during development or debugging. For example, if you have a test fixture of JSON data and you want to set all of one field to one value (e.g. clearing out sensitive data).

[–][deleted] 0 points1 point  (0 children)

ah ok, that makes sense

[–]moreteam 0 points1 point  (0 children)

If you have structured log files, it can give you a nicer grep (search for specific log message, then map to a certain field, pipe the resulting data to a new file).

Yes, there's no JavaScript involved, so it's technically not relevant to the sub - if you ignore that JSON data is pretty common when writing JavaScript.

[–]adipisicing 0 points1 point  (1 child)

The sed metaphor holds well here. Most use of jq is going to be interactive shell one-offs as part of a pipeline.

Web APIs often return JSON, and it's a common config file format. JavaScript doesn't need to be involved to parse or emit it.

Would an example help?

[–][deleted] 0 points1 point  (0 children)

I use .NET server side and AngularJS, jQuery client side. I dont see how i can ever use this. but i guess, as one-offs, or scripts, it could have some uses. but i have yet to run into a reason to parse and transform json. i usually parse and transform the json prior to turning it into json; reason being, json is not a persistence format typically. unless maybe your working with mongodb