All Projects → mohd-akram → jawk

mohd-akram / jawk

Licence: MIT License
Awk for JSON.

Programming Languages

shell
77523 projects
awk
318 projects
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to jawk

jobflow
runs stuff in parallel (like GNU parallel, but much faster and memory-efficient)
Stars: ✭ 67 (+109.38%)
Mutual labels:  unix
unixstring
An FFI-friendly null-terminated byte string
Stars: ✭ 19 (-40.62%)
Mutual labels:  unix
dotpr0n
Dotfiles for macOS, FreeBSD, fish, tmux, custom functions and lots more. Peekaboo!
Stars: ✭ 44 (+37.5%)
Mutual labels:  unix
mrouted
The original DVMRP (dynamic multicast routing) implementation for UNIX
Stars: ✭ 58 (+81.25%)
Mutual labels:  unix
apex
ANSI POSIX Environment neXt for Harvey OS
Stars: ✭ 25 (-21.87%)
Mutual labels:  unix
GLFW-CMake-starter
Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS.
Stars: ✭ 53 (+65.63%)
Mutual labels:  unix
pv
Unix Pipe Viewer (pv) utility in Node.js
Stars: ✭ 20 (-37.5%)
Mutual labels:  unix
x11-cr
X11 bindings for Crystal language.
Stars: ✭ 32 (+0%)
Mutual labels:  unix
skabus
A collection of tools to implement a simple Unix bus. https://skarnet.org/software/skabus/
Stars: ✭ 17 (-46.87%)
Mutual labels:  unix
TUI
Terminal user interface library. Works on *NIX and Windows systems
Stars: ✭ 32 (+0%)
Mutual labels:  unix
expandvars
Expand system variables Unix style
Stars: ✭ 17 (-46.87%)
Mutual labels:  unix
findlargedir
find all "blackhole" directories with a huge amount of filesystem entries in a flat structure
Stars: ✭ 15 (-53.12%)
Mutual labels:  unix
Sistem-programlama
Sistem Programlama Türkçe Kaynak (KTÜ)
Stars: ✭ 30 (-6.25%)
Mutual labels:  unix
bash-streams-handbook
💻 Learn Bash streams, pipelines and redirection, from beginner to advanced.
Stars: ✭ 153 (+378.13%)
Mutual labels:  unix
fil
😋 Unix file command written in Go
Stars: ✭ 69 (+115.63%)
Mutual labels:  unix
OpenBSDFirewall
Simple OpenBSD Home Firewall Config for ALIX Board
Stars: ✭ 41 (+28.13%)
Mutual labels:  unix
bspwm-config
Green themed bspwm configuration for ricing lovers
Stars: ✭ 19 (-40.62%)
Mutual labels:  unix
gosh
A primitive shell written in go.
Stars: ✭ 37 (+15.63%)
Mutual labels:  unix
dotfiles
🏡 .files, including zsh, tmux, vim, and git. Also macOS setup. Good stuff.
Stars: ✭ 30 (-6.25%)
Mutual labels:  unix
configs
all config files that I use/used
Stars: ✭ 14 (-56.25%)
Mutual labels:  unix

jawk

awk for JSON.

Install

Run make install as root to install jawk to /usr/local/bin.

or

Copy the jawk file to somewhere in your PATH.

Examples

$ echo '{"age":10}' | jawk '{print _["age"]}'
10

$ echo '{"person":{"name":"Jason"}}' | jawk '{print _["person","name"]}'
Jason

$ echo '[4,2,0]' | jawk '{while (++i <= _["length"]) print _[i]}'
4
2
0

$ echo '[{"x":6},{"x":7}]' | jawk '{while (++i <= _["length"]) print _[i,"x"]}'
6
7

$ printf '{"x":6}\n{"x":7}\n' | jawk '{print _["x"]}'
6
7

$ echo '{"name":{"first":"Jason"},"age":25}' | jawk '{
	keys(o); for (k in o) print k, _[o[k],JSON]
}'
name {"first":"Jason"}
age 25

$ echo '{"name":"Jason"}' | jawk '{print _["name",JSON]}'
"Jason"

# Try it with real data!
curl -Ls https://api.github.com/repos/onetrueawk/awk |
jawk '{print "id:", _["id"], "owner.id:", _["owner","id"]}'

curl -Ls https://api.github.com/repos/onetrueawk/awk/commits |
jawk '{
	while (++i <= _["length"]) {
		sha = _[i,"sha"]
		message = _[i,"commit","message"]
		l = index(message, "\n")
		print sha, substr(message, 1, l ? l - 1 : 50)
	}
}'

curl -Ls https://api.github.com/repos/onetrueawk/awk/commits |
jawk '{while (++i <= _["length"]) printf("{\"sha\":%s}\n",_[i,"sha",JSON])}'

Details

jawk makes available each JSON object using the _ variable. jawk programs are awk programs, and all awk features and functions are available. Nested fields can be accessed using standard awk indexing (eg. _["foo","bar"]). Some conversions are done: the value true is converted to 1, false is converted to 0 and null is converted to "". Arrays are 1-indexed.

Properties

_[p]

Return the value of the object at path p if it's a primitive, or p if it's an object or array. If the root object is a primitive, _[0] returns its value.

_[[p,]"length"]

Return the length of the array at path p, or the root array if p is omitted.

_[[p,]JSON]

Return the JSON form of the object at path p, or the root object if p is omitted.

_[[p,]TYPE]

Return the type of the object at path p, or the root object if p is omitted. The result will be one of boolean, null, array, object, string or number.

Functions

keys(a[, o])

Populate the array a with the keys of the object at path o such that a[k] = p where k is the key and p is its full path. The path can then be passed to _ to retrieve its value. If o isn't provided, a is populated with the keys and paths of the root object. Returns the number of keys.

Development

Make changes to src/jawk.sh and run make to produce jawk. Run make -B test to test changes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].