{"id":1087,"date":"2022-02-22T01:43:56","date_gmt":"2022-02-22T06:43:56","guid":{"rendered":"https:\/\/www.brunerd.com\/blog\/?p=1087"},"modified":"2022-02-25T15:23:12","modified_gmt":"2022-02-25T20:23:12","slug":"ljt-1-0-0-a-little-json-tool-for-your-shell-script","status":"publish","type":"post","link":"https:\/\/www.brunerd.com\/blog\/2022\/02\/22\/ljt-1-0-0-a-little-json-tool-for-your-shell-script\/","title":{"rendered":"ljt, a little JSON tool for your shell script"},"content":{"rendered":"\n<p><code>ljt<\/code>, the Little JSON Tool, is a concise and focused tool for quickly <strong>getting<\/strong> values from JSON and nothing else. It can be used standalone or embedded in your shell scripts. It requires only macOS 10.11+ or a *nix distro with <a rel=\"noreferrer noopener\" href=\"https:\/\/trac.webkit.org\/wiki\/JavaScriptCore\" target=\"_blank\">jsc<\/a> installed. It has no other dependencies.<\/p>\n\n\n\n<p>You might have also seen my other project <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/jpt\" target=\"_blank\">jpt<\/a>, the JSON Power Tool. It too can be used standalone or embedded in a script however its features and size (64k) might be overkill in some case and I get it! I thought the same thing too after I looked at work of <a rel=\"noreferrer noopener\" href=\"https:\/\/www.macblog.org\/posts\/how-to-parse-json-macos-command-line\/\" target=\"_blank\">Mathew Warren<\/a>, <a href=\"https:\/\/paulgalow.com\/how-to-work-with-json-api-data-in-macos-shell-scripts\">Paul Galow<\/a>, and <a rel=\"noreferrer noopener\" href=\"https:\/\/richard-purves.com\/2021\/12\/09\/jamf-pro-api-for-fun-and-profit\/\" target=\"_blank\">Richard Purves<\/a>. Sometimes you don&#8217;t need to process JSON Text Sequences, use advanced JSONPath querying, modify JSON, or encode the output in a myriad of ways. Maybe all you need is something to retrieve a JSON value in your shell script.<\/p>\n\n\n\n<p>Where jpt was an exercise in maximalism, ljt is one of essential minimalism \u2013 or at least as minimal as this <a rel=\"noreferrer noopener\" href=\"https:\/\/www.gallup.com\/cliftonstrengths\/en\/252299\/maximizer-theme.aspx\" target=\"_blank\">CliftonStrengths Maximizer<\/a> can go! \ud83e\udd13 The minified version is mere 1.2k and offers a bit more security and functionality than a one-liner.<\/p>\n\n\n\n<p><code>ljt<\/code> features:<br>\u2022 Query using JSON Pointer or JSONPath (canonical only, no filters, unions, etc)<br>\u2022 Javascript code injection prevention for both JSON and the query<br>\u2022 Multiple input methods: file redirection, file path, here doc, here string and Unix pipe<br>\u2022 Output of JSON strings as regular text and JSON for all others<br>\u2022 Maximum input size of 2GB and max output of 720MB (Note: functions that take JSON data as an environment variable or an argument are limited to a maximum of 1MB of data)<br>\u2022&nbsp;Zero and non-zero exit statuses for success and failure, respectively<\/p>\n\n\n\n<p>Swing by the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/ljt\" target=\"_blank\">ljt Github<\/a> page and check it out. There are two versions of the tool one is fully commented for studying and hacking (ljt), the other is a &#8220;minified&#8221; version without any comments meant for embedding into <em>your<\/em> shell scripts (ljt.min). The <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/ljt\/releases\" target=\"_blank\">Releases<\/a> page has a macOS pkg package to install and run <code>ljt<\/code> as a standalone utility. <\/p>\n\n\n\n<p>Thanks for reading and happy scripting!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ljt, the Little JSON Tool, is a concise and focused tool for quickly getting values from JSON and nothing else. It can be used standalone or embedded in your shell scripts. It requires only macOS 10.11+ or a *nix distro with jsc installed. It has no other dependencies. You might have also seen my other [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,38,37,51,41,53,12,39],"tags":[],"class_list":["post-1087","post","type-post","status-publish","format-standard","hentry","category-bash","category-javascript","category-jpt","category-json","category-jsonpath","category-ljt","category-scripting","category-zsh"],"_links":{"self":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/1087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/comments?post=1087"}],"version-history":[{"count":9,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/1087\/revisions"}],"predecessor-version":[{"id":1103,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/1087\/revisions\/1103"}],"wp:attachment":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/media?parent=1087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/categories?post=1087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/tags?post=1087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}