shithub: json2awk


branches: front

Clone

clone: git://shithub.us/akw/json2awk gits://shithub.us/akw/json2awk
push: hjgit://shithub.us/akw/json2awk
patches to: akw@oneiri.one

Last commit

f8d74ea1 – Aidan Wiggins <akw@oneiri.one> authored on 2026/03/26 22:37
handle empty input and fmt output of example

About

json2awk outputs awk array definitions for json structures:

	{
		"Image": {
			"Width":  800,
			"Height": 600,
			"Title":  "View from 15th Floor",
			"Thumbnail": {
				"Url":    "http://www.example.com/image/481989943",
				"Height": 125,
				"Width":  100
			},
			"Animated" : false,
			"IDs": [116, 943, 234, 38793]
		}
	}

yields:

	json["Image", "Width"] = 800;
	json["Image", "Height"] = 600;
	json["Image", "Title"] = "View from 15th Floor";
	json["Image", "Thumbnail", "Url"] = "http://www.example.com/image/481989943";
	json["Image", "Thumbnail", "Height"] = 125;
	json["Image", "Thumbnail", "Width"] = 100;
	json["Image", "Animated"] = 0;
	json["Image", "IDs", 0] = 116;
	json["Image", "IDs", 1] = 943;
	json["Image", "IDs", 2] = 234;
	json["Image", "IDs", 3] = 38793;

chaos ensues

also included is a helper script "jawk" which takes via standard input
some json data, and runs an awk BEGIN statement with json2awk
definitions preceding a second argument string containing awk
statements.  see weather.rc for a complete example (you'll have to
change street= and zip= … US addressing), it prints a weather report
using weather.gov's API.