{"id":5872,"date":"2015-12-22T15:07:57","date_gmt":"2015-12-22T14:07:57","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/hayek\/jochen\/wp\/blog-en\/?p=5872"},"modified":"2020-09-30T20:23:45","modified_gmt":"2020-09-30T18:23:45","slug":"jq-json-processor","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2015\/12\/22\/jq-json-processor\/","title":{"rendered":"Stephen Dolan&#8217;s &#8220;jq&#8221; is a lightweight and flexible command-line JSON processor"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/stedolan.github.io\/jq\/\">https:\/\/stedolan.github.io\/jq\/<\/a><\/li><li><a href=\"https:\/\/stedolan.github.io\/jq\/tutorial\/\">https:\/\/stedolan.github.io\/jq\/tutorial\/<\/a><\/li><li><a href=\"https:\/\/stedolan.github.io\/jq\/manual\/\">https:\/\/stedolan.github.io\/jq\/manual\/<\/a><\/li><li><a href=\"https:\/\/github.com\/stedolan\/jq\">https:\/\/github.com\/stedolan\/jq<\/a><\/li><li><a href=\"https:\/\/github.com\/stedolan\/jq\/wiki\">https:\/\/github.com\/stedolan\/jq\/wiki<\/a><\/li><li><a href=\"https:\/\/github.com\/stedolan\/jq\/wiki\/Cookbook\">https:\/\/github.com\/stedolan\/jq\/wiki\/Cookbook<\/a><\/li><li><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/jq\">https:\/\/stackoverflow.com\/questions\/tagged\/jq<\/a><\/li><li><a href=\"http:\/\/shop.oreilly.com\/product\/0636920032823.do\">http:\/\/shop.oreilly.com\/product\/0636920032823.do<\/a>&nbsp;\u2013 o&#8217;Reilly &#8220;<em>Data Science at the Command Line<\/em>&#8221; \u2013&nbsp;has some examples making use of <em>jq<\/em><\/li><li><a href=\"https:\/\/library.oreilly.com\/book\/0636920032823\/data-science-at-the-command-line\/84.xhtml?ref=toc#_jq\">https:\/\/library.oreilly.com\/book\/0636920032823\/data-science-at-the-command-line\/84.xhtml?ref=toc#_jq<\/a>&nbsp;\u2013 behind a paywall<\/li><li>available as source (portable C) and as executables for various Intel-based platforms, i.e. some Linux distributions, Mac OS X, Windows incl. Cygwin<\/li><li><a href=\"https:\/\/cygwin.com\/packages\/x86_64\/jq\/\">https:\/\/cygwin.com\/packages\/x86_64\/jq\/<\/a><\/li><li><a href=\"https:\/\/www.safaribooksonline.com\/library\/view\/json-at-work\/9781491982389\/ch06.html#json_search\">https:\/\/www.safaribooksonline.com\/library\/view\/json-at-work\/9781491982389\/ch06.html#json_search<\/a> : \u2026, <code>jq<\/code>, <code>jqPlay<\/code>, <code>jq-tutorial<\/code>, \u2026<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">&#8220;<em>jq<\/em>&#8221; (presumably) stands for &#8220;<span style=\"text-decoration: underline;\">J<\/span>SON <span style=\"text-decoration: underline;\">q<\/span>uery processor&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>jq<\/em> helps writing shell scripts processing JSON responses from e.g. RESTful application APIs like Jenkins, Atlassian JIRA, Atlassian Confluence, \u2026 \u2013 code making use&nbsp;of powerful means&nbsp;like <em>XPath<\/em> (\u2026) or&nbsp;<em>jq<\/em>&nbsp;is supposedly far more readable than Python \/ Perl \/ \u2026 scripts slurping the JSON and processing it (w\/o <em>jq<\/em> resp. <em>XPath<\/em>) \u2013 but there are also Python resp. Perl bindings for <em>jq<\/em>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Hope and fear<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"line-height: 1.75;\">A couple of weeks ago&nbsp;I had written a shell script querying a Jenkins server&#8217;s REST API &#8220;\u00e0 la XML&#8221;. Now&nbsp;it looks a little straighter to query the API &#8220;\u00e0 la JSON&#8221; and&nbsp;employ&nbsp;<\/span><em style=\"line-height: 1.75;\">jq<\/em><span style=\"line-height: 1.75;\">. But the critical question is, whether the (industrial) customer (I wrote the Jenkins utility for) will like the dependency on a utility like <\/span><em style=\"line-height: 1.75;\">jq<\/em><span style=\"line-height: 1.75;\">. My Jenkins utility might have to serve for quite a couple of years \u2013 but who can predict the future and availability of <\/span><em style=\"line-height: 1.75;\">jq<\/em><span style=\"line-height: 1.75;\">?<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Update 2016-02-23: Meanwhile I built a shell script with a couple of simple jq queries accessing Jenkins CI. Looks rather impressive to me.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you do XPath queries from shell scripts, you always have the option to rewrite the shell script as Python or Perl script. But what about JSON queries (&#8230;) in Python or Perl?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/pypi.python.org\/pypi\/jq\">https:\/\/pypi.python.org\/pypi\/jq<\/a><\/li><li><a href=\"https:\/\/github.com\/spiritloose\/JQ\">https:\/\/github.com\/spiritloose\/JQ<\/a>&nbsp;&#8212; &#8220;Perl binding for jq&#8221;<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/stedolan.github.io\/jq\/manual\/\">https:\/\/stedolan.github.io\/jq\/manual\/<\/a>&nbsp;:<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>By default, jq pretty-prints JSON output.<\/p><\/blockquote>\n\n\n\n<pre class=\"wp-block-preformatted\">$ jq . &lt; \u2026 &gt; \u2026<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/stedolan.github.io\/jq\/ https:\/\/stedolan.github.io\/jq\/tutorial\/ https:\/\/stedolan.github.io\/jq\/manual\/ https:\/\/github.com\/stedolan\/jq https:\/\/github.com\/stedolan\/jq\/wiki https:\/\/github.com\/stedolan\/jq\/wiki\/Cookbook https:\/\/stackoverflow.com\/questions\/tagged\/jq http:\/\/shop.oreilly.com\/product\/0636920032823.do&nbsp;\u2013 o&#8217;Reilly &#8220;Data Science at the Command Line&#8221; \u2013&nbsp;has some examples making use of jq https:\/\/library.oreilly.com\/book\/0636920032823\/data-science-at-the-command-line\/84.xhtml?ref=toc#_jq&nbsp;\u2013 behind a paywall available as source (portable C) and as executables for various Intel-based platforms, i.e. some Linux distributions, Mac OS X, Windows incl. Cygwin https:\/\/cygwin.com\/packages\/x86_64\/jq\/ https:\/\/www.safaribooksonline.com\/library\/view\/json-at-work\/9781491982389\/ch06.html#json_search : \u2026, jq, jqPlay, jq-tutorial, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_share_on_mastodon":"0"},"categories":[29,82,289],"tags":[1126,1130],"class_list":["post-5872","post","type-post","status-publish","format-standard","hentry","category-atlassian-jira","category-cygwin","category-json","tag-jq","tag-json-tidy"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-1wI","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/comments?post=5872"}],"version-history":[{"count":1,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5872\/revisions"}],"predecessor-version":[{"id":11338,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5872\/revisions\/11338"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=5872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=5872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=5872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}