(Request started in PR #11)
The current method for embedding JSON.awk in a larger awk application requires modifying JSON.awk by editing stub function apply. Can a new embedding method be defined that doesn't require modifying the JSON.awk script, and that works across POSIX awk, mawk and gawk?
For instance, the following method (not tested, suggested in #11) leverages gawk's @include statement, which POSIX awk and mawk don't support.
$ declare -A "$(aws deploy get-deployment --deployment-id $DEPLOYMENT_ID \
|awk -v STREAM=0 -v ARRAY="DEPLOYMENT_GITHUB" -v KEYS='"deploymentInfo","revision","gitHubLocation","(commitId|repository)"' '
@include "json.awk";
{
array = sprintf("%s=(",ARRAY);
regex = "["KEYS"]";
for (key in JPATHS) {
if( JPATHS[key] ~ KEYS ) {
n=patsplit(JPATHS[key], path, "\"([^\"]+)\"");
array = sprintf("%s [%s]=%s", array, path[n-1], path[n]);
}
}
array = sprintf("%s )", array);
printf "%s", array;
}' -
)"
$ echo $DEPLOYMENT_GITHUB['repository'];
$ echo $DEPLOYMENT_GITHUB['commitId'];
(Request started in PR #11)
The current method for embedding JSON.awk in a larger awk application requires modifying JSON.awk by editing stub function
apply. Can a new embedding method be defined that doesn't require modifying the JSON.awk script, and that works across POSIX awk, mawk and gawk?For instance, the following method (not tested, suggested in #11) leverages gawk's
@includestatement, which POSIX awk and mawk don't support.