{"id":13897734,"url":"https://github.com/mohd-akram/jawk","last_synced_at":"2025-04-13T11:43:23.707Z","repository":{"id":41446458,"uuid":"286324304","full_name":"mohd-akram/jawk","owner":"mohd-akram","description":"Awk for JSON.","archived":false,"fork":false,"pushed_at":"2025-03-11T15:36:58.000Z","size":60,"stargazers_count":42,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T02:51:18.454Z","etag":null,"topics":["awk","json","shell","unix"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohd-akram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-08-09T22:06:56.000Z","updated_at":"2025-03-11T15:37:02.000Z","dependencies_parsed_at":"2024-01-15T16:43:49.259Z","dependency_job_id":"d52634d2-ede7-4241-b938-b3aa92387add","html_url":"https://github.com/mohd-akram/jawk","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohd-akram%2Fjawk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohd-akram%2Fjawk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohd-akram%2Fjawk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohd-akram%2Fjawk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohd-akram","download_url":"https://codeload.github.com/mohd-akram/jawk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248709981,"owners_count":21149185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["awk","json","shell","unix"],"created_at":"2024-08-06T18:03:50.540Z","updated_at":"2025-04-13T11:43:23.670Z","avatar_url":"https://github.com/mohd-akram.png","language":"Shell","readme":"# jawk\n\nawk for JSON.\n\n## Install\n\nRun `make install` as root to install `jawk` to `/usr/local/bin`.\n\nor\n\nCopy the `jawk` file to somewhere in your `PATH`.\n\n## Examples\n\n```shell\n$ echo '{\"age\":10}' | jawk '{print _[\"age\"]}'\n10\n\n$ echo '{\"person\":{\"name\":\"Jason\"}}' | jawk '{print _[\"person\",\"name\"]}'\nJason\n\n$ echo '[4,2,0]' | jawk '{while (++i \u003c= _[\"length\"]) print _[i]}'\n4\n2\n0\n\n$ echo '[{\"x\":6},{\"x\":7}]' | jawk '{while (++i \u003c= _[\"length\"]) print _[i,\"x\"]}'\n6\n7\n\n$ printf '{\"x\":6}\\n{\"x\":7}\\n' | jawk '{print _[\"x\"]}'\n6\n7\n\n$ echo '{\"name\":{\"first\":\"Jason\"},\"age\":25}' | jawk '{\n\tkeys(o); for (k in o) print k, _[o[k],JSON]\n}'\nname {\"first\":\"Jason\"}\nage 25\n\n$ echo '{\"name\":\"Jason\"}' | jawk '{print _[\"name\",JSON]}'\n\"Jason\"\n\n# Try it with real data!\ncurl -Ls https://api.github.com/repos/onetrueawk/awk |\njawk '{print \"id:\", _[\"id\"], \"owner.id:\", _[\"owner\",\"id\"]}'\n\ncurl -Ls https://api.github.com/repos/onetrueawk/awk/commits |\njawk '{\n\twhile (++i \u003c= _[\"length\"]) {\n\t\tsha = _[i,\"sha\"]\n\t\tmessage = _[i,\"commit\",\"message\"]\n\t\tl = index(message, \"\\n\")\n\t\tprint sha, substr(message, 1, l ? l - 1 : 50)\n\t}\n}'\n\ncurl -Ls https://api.github.com/repos/onetrueawk/awk/commits |\njawk '{while (++i \u003c= _[\"length\"]) printf(\"{\\\"sha\\\":%s}\\n\",_[i,\"sha\",JSON])}'\n```\n\n## Details\n\njawk makes available each JSON object using the `_` variable. `jawk` programs\nare `awk` programs, and all `awk` features and functions are available. Nested\nfields can be accessed using standard awk indexing (eg. `_[\"foo\",\"bar\"]`).\nSome conversions are done: the value `true` is converted to 1, `false` is\nconverted to 0 and `null` is converted to `\"\"`. Arrays are 1-indexed.\n\n## Properties\n\n### _[p]\n\nReturn the value of the object at path `p` if it's a primitive, or `p` if it's\nan object or array. If the root object is a primitive, `_[0]` returns its\nvalue.\n\n### _[[p,]\"length\"]\n\nReturn the length of the array at path `p`, or the root array if `p` is\nomitted.\n\n### _[[p,]JSON]\n\nReturn the JSON form of the object at path `p`, or the root object if `p` is\nomitted.\n\n### _[[p,]TYPE]\n\nReturn the type of the object at path `p`, or the root object if `p` is\nomitted. The result will be one of `boolean`, `null`, `array`, `object`,\n`string` or `number`.\n\n## Functions\n\n### keys(a[, o])\n\nPopulate the array `a` with the keys of the object at path `o` such that `a[k]\n= p` where `k` is the key and `p` is its full path. The path can then be passed\nto `_` to retrieve its value. If `o` isn't provided, `a` is populated with the\nkeys and paths of the root object. Returns the number of keys.\n\n## Development\n\nMake changes to `src/jawk.sh` and run `make` to produce `jawk`. Run `make -B\ntest` to test changes.\n","funding_links":[],"categories":["Shell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohd-akram%2Fjawk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohd-akram%2Fjawk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohd-akram%2Fjawk/lists"}