To parse JSON in awk, you can use a combination of tokenization and recursive parsing. Below is a function that converts a JSON string into an associative array with keys representing the JSON structure's hierarchy (e.g., object.key.array[0]
):
function tokenize(json, tokens, pos, len, c, regex, match_str) {
pos = 1
len = length(json)
delete tokens
while (pos <= len) {
# Skip whitespace