#!/bin/bash json=$(1)); do printf "%*s" "$indent"; print "$array"; printf ",\n" array=("${array[@]:1}") done printf "%*s" "$indent"; print "$array" printf "\n%*s]" "$((indent-=2))" fi ;; obj*) local object=(${obj_list[rt[${1:3}]]}) if ((!${#object[@]})); then printf "{}" else ((indent+=2)); printf "{\n" while ((${#object[@]}>2)); do printf "%*s" "$indent"; print "$object"; printf ": " print "${object[1]}"; printf ",\n" object=("${object[@]:2}") done printf "%*s" "$indent"; print "$object"; printf ": " print "${object[1]}"; printf "\n" printf "%*s}" "$((indent-=2))" fi ;; esac # field extraction for arg do # plenty of error checking here! case $arg in obj*) [[ $json = obj* ]] || { json=null; break; } json=${obj_list[rt[${json:3}]]} object=($json) while ((${#object[@]})); do if [[ ${str_list[rt[${object:3}]]} = "${arg:5}" ]]; then json=${object[1]} continue 2 else object=("${object[@]:2}") fi done json=null; break ;; arr*) [[ $json = arr* ]] || { json=null; break; } json=${arr_list[rt[${json:3}]]} array=($json) ((${#array[@]} >= ${arg:5} )) || { json=null; break; } json=${array[${arg:5}]} ;; esac done print "$json"; echo