update json wrapper tools
The json wrapper tools, `bin/jfmt-wrapper.sh`, `bin/jprint-wrapper.sh` and `bin/jval-wrapper.sh` have been updated as follows: The `-Q` option now does a quick test, ignores args, and exits. With `-Q`, the required args are ignored and are not required. The quick testing of `JSONPath.sh` via `-Q` is fixed. Leading commends about the tools have improved. A few typos have been fixed. The `-v 3` variable printing is performed just before any `-N` test. Changed `bin/jfmt-wrapper.sh` VERSION from "2.0.1 2025-04-21" to "2.0.2 2025-05-04". Changed `bin/jprint-wrapper.sh` VERSION from "2.0.1 2025-04-21" to "2.0.2 2025-05-04". Changed `bin/jval-wrapper.sh` VERSION from "2.0.1 2025-04-21" to "2.0.2 2025-05-04". Updated sitemap. Tested the above via `make update` on macOS.
This commit is contained in:
1 parent
b190c12658
commit
3dcc1d44b9
4 files changed
+362
-270
No files matched your search
+122
-95
@@ -2,10 +2,10 @@
|
||||
#
|
||||
# jfmt-wrapper.sh - canonically format a JSON file
|
||||
#
|
||||
# If the JSON file is already on canonical form, the file is not modified.
|
||||
#
|
||||
# We form a wrapper for the jprint(1), a tool that will format a JSON
|
||||
# file into a canonical style.
|
||||
# file into a canonical JSON style.
|
||||
#
|
||||
# If the JSON file is already on canonical form, the file is not modified.
|
||||
#
|
||||
# NOTE: As of 2024 Sep 10 the jprint(1) tool has not been written,
|
||||
# so jfmt-wrapper.sh uses the jsp tool from:
|
||||
@@ -26,7 +26,7 @@
|
||||
#
|
||||
# https://github.com/lcn2/JSONPath.sh
|
||||
#
|
||||
# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved.
|
||||
# Copyright (c) 2024-2025 by Landon Curt Noll. All Rights Reserved.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and
|
||||
# its documentation for any purpose and without fee is hereby granted,
|
||||
@@ -128,7 +128,7 @@ export LC_ALL="C"
|
||||
|
||||
# set variables referenced in the usage message
|
||||
#
|
||||
export VERSION="2.0.1 2025-04-21"
|
||||
export VERSION="2.0.2 2025-05-04"
|
||||
NAME=$(basename "$0")
|
||||
export NAME
|
||||
export V_FLAG=0
|
||||
@@ -181,9 +181,9 @@ export USAGE="usage: $0 [-h] [-v level] [-V] [-n] [-N] [-t tool] [-Q] file.json
|
||||
-N do not process file, just parse arguments and ignore the file (def: process the file)
|
||||
|
||||
-t tool tool to use: jsp or JSONPath.sh (def: try jsp, otherwise try JSONPath.sh)
|
||||
-Q quick check tool using trivial input (def: do not)
|
||||
-Q quick check tool using trivial input and exit, ignore file.json and pattern (def: do not)
|
||||
|
||||
file.json update file.json in canonical form
|
||||
file.json JSON file to read, - ==> read stdin (ignored if -Q)
|
||||
|
||||
NOTE: file.json is not touched if it is already in canonical form
|
||||
|
||||
@@ -267,6 +267,12 @@ if [[ $V_FLAG -ge 1 ]]; then
|
||||
fi
|
||||
export JSON_FILE=
|
||||
case "$#" in
|
||||
0) if [[ -z $QUICK_CHECK ]]; then
|
||||
echo "$0: ERROR: 0 args allowed only with -Q" 1>&2
|
||||
echo "$USAGE" 1>&2
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
1) JSON_FILE="$1" ;;
|
||||
*) echo "$0: ERROR: expected 1 arg, found: $#" 1>&2
|
||||
echo 1>&2
|
||||
@@ -275,17 +281,24 @@ case "$#" in
|
||||
;;
|
||||
esac
|
||||
#
|
||||
if [[ ! -e $JSON_FILE ]]; then
|
||||
echo "$0: ERROR: JSON_FILE does not exist: $JSON_FILE" 1>&2
|
||||
exit 6
|
||||
fi
|
||||
if [[ ! -f $JSON_FILE ]]; then
|
||||
echo "$0: ERROR: JSON_FILE is not a regular file: $JSON_FILE" 1>&2
|
||||
exit 6
|
||||
fi
|
||||
if [[ ! -r $JSON_FILE ]]; then
|
||||
echo "$0: ERROR: JSON_FILE is not an readable file: $JSON_FILE" 1>&2
|
||||
exit 6
|
||||
# -Q ignores ignore file.json
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
JSON_FILE=""
|
||||
#
|
||||
else
|
||||
if [[ ! -e $JSON_FILE ]]; then
|
||||
echo "$0: ERROR: JSON_FILE does not exist: $JSON_FILE" 1>&2
|
||||
exit 6
|
||||
fi
|
||||
if [[ ! -f $JSON_FILE ]]; then
|
||||
echo "$0: ERROR: JSON_FILE is not a regular file: $JSON_FILE" 1>&2
|
||||
exit 6
|
||||
fi
|
||||
if [[ ! -r $JSON_FILE ]]; then
|
||||
echo "$0: ERROR: JSON_FILE is not an readable file: $JSON_FILE" 1>&2
|
||||
exit 6
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -344,83 +357,6 @@ fi
|
||||
export BIN_DIR="bin"
|
||||
|
||||
|
||||
# validate the XPath for JSON tool
|
||||
#
|
||||
case "$XPATHJSON_USE" in
|
||||
|
||||
# case: we will use JSONPath.sh
|
||||
#
|
||||
JSONPath.sh)
|
||||
|
||||
# try JSONPath.sh
|
||||
#
|
||||
if [[ -z $JSONPATH_SH || ! -x $JSONPATH_SH ]]; then
|
||||
echo "$0: ERROR: JSONPath.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify JSONPath.sh supports -S -4 -p
|
||||
if ! "$JSONPATH_SH" -S -4 -p >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: JSONPath.sh tool does not support -S -4 -p: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we will use jsp
|
||||
#
|
||||
jsp)
|
||||
|
||||
# try jsp
|
||||
#
|
||||
if [[ -z $JSP_TOOL || ! -x $JSP_TOOL ]]; then
|
||||
echo "$0: ERROR: jsp.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify jsp
|
||||
if ! "$JSP_TOOL" --indent 4 --format --no-color >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: jsp tool does not support --indent 4 --format --no-color: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: you might need to update and reinstall jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: or you might try to obtain and install JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we do not have an XPath for JSON tool
|
||||
#
|
||||
*)
|
||||
echo "$0: ERROR: cannot find an XPath JSON tool to use" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# print running info if verbose
|
||||
#
|
||||
# If -v 3 or higher, print exported variables in order that they were exported.
|
||||
@@ -474,6 +410,97 @@ if [[ -n $DO_NOT_PROCESS ]]; then
|
||||
fi
|
||||
|
||||
|
||||
# validate the XPath for JSON tool
|
||||
#
|
||||
case "$XPATHJSON_USE" in
|
||||
|
||||
# case: we will use JSONPath.sh
|
||||
#
|
||||
JSONPath.sh)
|
||||
|
||||
# try JSONPath.sh
|
||||
#
|
||||
if [[ -z $JSONPATH_SH || ! -x $JSONPATH_SH ]]; then
|
||||
echo "$0: ERROR: JSONPath.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify JSONPath.sh supports -S -4
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: about to: $JSONPATH_SH -S -4 >/dev/null 2>&1 <<< $FIZZBIN_JSON" 1>&2
|
||||
fi
|
||||
if ! "$JSONPATH_SH" -S -4 >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: JSONPath.sh tool does not support -S -4 $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: passed quick check: $JSONPATH_SH" 1>&2
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we will use jsp
|
||||
#
|
||||
jsp)
|
||||
|
||||
# try jsp
|
||||
#
|
||||
if [[ -z $JSP_TOOL || ! -x $JSP_TOOL ]]; then
|
||||
echo "$0: ERROR: jsp.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify jsp
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: about to: $JSP_TOOL --indent 4 --format --no-color >/dev/null 2>&1 <<< $FIZZBIN_JSON" 1>&2
|
||||
fi
|
||||
if ! "$JSP_TOOL" --indent 4 --format --no-color >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: jsp tool does not support --indent 4 --format --no-color: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: you might need to update and reinstall jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: or you might try to obtain and install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: passed quick check: $JSP_TOOL" 1>&2
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we do not have an XPath for JSON tool
|
||||
#
|
||||
*)
|
||||
echo "$0: ERROR: cannot find an XPath JSON tool to use" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# create a temporary entry JSON file
|
||||
#
|
||||
export TMP_JSON_FILE=".tmp.$NAME.JSON_FILE.$$.tmp"
|
||||
|
||||
+103
-84
@@ -7,8 +7,7 @@
|
||||
# We form a wrapper for the jprint(1), a tool that will format a JSON
|
||||
# file into a canonical style.
|
||||
#
|
||||
# NOTE: As of 2024 Sep 09 the jprint(1) tool has not been written,
|
||||
# so jprint-wrapper.sh uses with the jsp tool from:
|
||||
# NOTE: As of 2024 Sep 09 the jprint(1) tool has not been written, so jprint-wrapper.sh uses with the jsp tool from:
|
||||
#
|
||||
# https://github.com/kjozsa/jsp
|
||||
#
|
||||
@@ -26,7 +25,7 @@
|
||||
#
|
||||
# https://github.com/lcn2/JSONPath.sh
|
||||
#
|
||||
# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved.
|
||||
# Copyright (c) 2024-2025 by Landon Curt Noll. All Rights Reserved.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and
|
||||
# its documentation for any purpose and without fee is hereby granted,
|
||||
@@ -128,7 +127,7 @@ export LC_ALL="C"
|
||||
|
||||
# set variables referenced in the usage message
|
||||
#
|
||||
export VERSION="2.0.1 2025-04-21"
|
||||
export VERSION="2.0.2 2025-05-04"
|
||||
NAME=$(basename "$0")
|
||||
export NAME
|
||||
export V_FLAG=0
|
||||
@@ -165,7 +164,7 @@ export JSP_TOOL=""
|
||||
JSP_TOOL=$(type -P jsp)
|
||||
export JSONPATH_SH=""
|
||||
JSONPATH_SH=$(type -P JSONPath.sh)
|
||||
# set the defaiult XPath for JSON
|
||||
# set the default XPath for JSON
|
||||
export XPATHJSON_USE="jsp"
|
||||
export QUICK_CHECK=""
|
||||
|
||||
@@ -182,9 +181,9 @@ export USAGE="usage: $0 [-h] [-v level] [-V] [-n] [-N] [-t tool] [-Q] [file.json
|
||||
-N do not process file, just parse arguments and ignore the file (def: process the file)
|
||||
|
||||
-t tool tool to use: jsp or JSONPath.sh (def: try jsp, otherwise try JSONPath.sh)
|
||||
-Q quick check tool using trivial input (def: do not)
|
||||
-Q quick check tool using trivial input and exit, ignore file.json (def: do not)
|
||||
|
||||
file.json The JSON file to write, in canonical form, to stdout (def: read stdin)
|
||||
file.json The JSON file to write, in canonical form, to stdout (def: read stdin) (ignored if -Q)
|
||||
|
||||
Exit codes:
|
||||
0 all OK
|
||||
@@ -274,6 +273,12 @@ case "$#" in
|
||||
;;
|
||||
esac
|
||||
#
|
||||
# -Q ignores ignore file.json
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
JSON_FILE=""
|
||||
fi
|
||||
#
|
||||
if [[ -n $JSON_FILE ]]; then
|
||||
if [[ ! -e $JSON_FILE ]]; then
|
||||
echo "$0: ERROR: JSON_FILE does not exist: $JSON_FILE" 1>&2
|
||||
@@ -345,83 +350,6 @@ fi
|
||||
export BIN_DIR="bin"
|
||||
|
||||
|
||||
# validate the XPath for JSON tool
|
||||
#
|
||||
case "$XPATHJSON_USE" in
|
||||
|
||||
# case: we will use JSONPath.sh
|
||||
#
|
||||
JSONPath.sh)
|
||||
|
||||
# try JSONPath.sh
|
||||
#
|
||||
if [[ -z $JSONPATH_SH || ! -x $JSONPATH_SH ]]; then
|
||||
echo "$0: ERROR: JSONPath.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify JSONPath.sh supports -S -4 -p
|
||||
if ! "$JSONPATH_SH" -S -4 -p >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: JSONPath.sh tool does not support -S -4 -p: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we will use jsp
|
||||
#
|
||||
jsp)
|
||||
|
||||
# try jsp
|
||||
#
|
||||
if [[ -z $JSP_TOOL || ! -x $JSP_TOOL ]]; then
|
||||
echo "$0: ERROR: jsp.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify jsp
|
||||
if ! "$JSP_TOOL" --indent 4 --format --no-color >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: jsp tool does not support --indent 4 --format --no-color: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: you might need to update and reinstall jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: or you might try to obtain and install JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we do not have an XPath for JSON tool
|
||||
#
|
||||
*)
|
||||
echo "$0: ERROR: cannot find an XPath JSON tool to use" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh version 0.0.22 or later from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# print running info if verbose
|
||||
#
|
||||
# If -v 3 or higher, print exported variables in order that they were exported.
|
||||
@@ -475,6 +403,97 @@ if [[ -n $DO_NOT_PROCESS ]]; then
|
||||
fi
|
||||
|
||||
|
||||
# validate the XPath for JSON tool
|
||||
#
|
||||
case "$XPATHJSON_USE" in
|
||||
|
||||
# case: we will use JSONPath.sh
|
||||
#
|
||||
JSONPath.sh)
|
||||
|
||||
# try JSONPath.sh
|
||||
#
|
||||
if [[ -z $JSONPATH_SH || ! -x $JSONPATH_SH ]]; then
|
||||
echo "$0: ERROR: JSONPath.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify JSONPath.sh supports -S -4
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: about to: $JSONPATH_SH -S -4 >/dev/null 2>&1 <<< $FIZZBIN_JSON" 1>&2
|
||||
fi
|
||||
if ! "$JSONPATH_SH" -S -4 >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: JSONPath.sh tool does not support -S -4 $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: passed quick check: $JSONPATH_SH" 1>&2
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we will use jsp
|
||||
#
|
||||
jsp)
|
||||
|
||||
# try jsp
|
||||
#
|
||||
if [[ -z $JSP_TOOL || ! -x $JSP_TOOL ]]; then
|
||||
echo "$0: ERROR: jsp.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify jsp
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: about to: $JSP_TOOL --indent 4 --format --no-color >/dev/null 2>&1 <<< $FIZZBIN_JSON" 1>&2
|
||||
fi
|
||||
if ! "$JSP_TOOL" --indent 4 --format --no-color >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: jsp tool does not support --indent 4 --format --no-color: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: you might need to update and reinstall jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: or you might try to obtain and install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: passed quick check: $JSP_TOOL" 1>&2
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we do not have an XPath for JSON tool
|
||||
#
|
||||
*)
|
||||
echo "$0: ERROR: cannot find an XPath JSON tool to use" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# -n means we have nothing to do
|
||||
#
|
||||
if [[ -n $NOOP ]]; then
|
||||
|
||||
+133
-87
@@ -1,8 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# jval-wrapper.sh - print JSON values to stdout using the XPath for JSON model
|
||||
# jval-wrapper.sh - write JSON values to stdout using the XPath for JSON model
|
||||
#
|
||||
# We form a wrapper for the `jval(1)`, a tool that allow the printing of JSON values.
|
||||
# We form a wrapper for the `jval(1)`, a tool that allow the printing JSON values to stdout
|
||||
# using the XPath for JSON model.
|
||||
#
|
||||
# NOTE: As of 2024 Sep 09 the jval(1) tool has not been written, so jval-wrapper.sh uses with the jsp tool from:
|
||||
#
|
||||
# https://github.com/kjozsa/jsp
|
||||
#
|
||||
# FYI: For macOS, use homebrew to install pipx:
|
||||
#
|
||||
# brew install pipx
|
||||
#
|
||||
# Next, use pipx to install jsp:
|
||||
#
|
||||
# pipx --global install jsp
|
||||
#
|
||||
# and then be sure that ~/.local/bin is in your $PATH.
|
||||
#
|
||||
# or the JSONPath.sh(1) tool from:
|
||||
#
|
||||
# https://github.com/lcn2/JSONPath.sh
|
||||
#
|
||||
# See the following on XPath for JSON model:
|
||||
#
|
||||
@@ -10,7 +29,7 @@
|
||||
# https://jsonpath.com
|
||||
# https://github.com/lcn2/JSONPath.sh?tab=readme-ov-file#jsonpath-patterns-and-extensions
|
||||
#
|
||||
# Copyright (c) 2024 by Landon Curt Noll. All Rights Reserved.
|
||||
# Copyright (c) 2024-2025 by Landon Curt Noll. All Rights Reserved.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and
|
||||
# its documentation for any purpose and without fee is hereby granted,
|
||||
@@ -112,7 +131,7 @@ export LC_ALL="C"
|
||||
|
||||
# set variables referenced in the usage message
|
||||
#
|
||||
export VERSION="2.0.1 2025-04-21"
|
||||
export VERSION="2.0.2 2025-05-04"
|
||||
NAME=$(basename "$0")
|
||||
export NAME
|
||||
export V_FLAG=0
|
||||
@@ -149,7 +168,7 @@ export JSP_TOOL=""
|
||||
JSP_TOOL=$(type -P jsp)
|
||||
export JSONPATH_SH=""
|
||||
JSONPATH_SH=$(type -P JSONPath.sh)
|
||||
# set the defaiult XPath for JSON
|
||||
# set the default XPath for JSON
|
||||
export XPATHJSON_USE="jsp"
|
||||
export JSONPATH_ARG
|
||||
export PATTERN=""
|
||||
@@ -176,14 +195,14 @@ export USAGE="usage: $0 [-h] [-v level] [-V] [-n] [-N] [-b] [-q] [-T] [-t tool]
|
||||
-T trim all newlines (def: do not)
|
||||
|
||||
-t tool tool to use: jsp or JSONPath.sh (def: try jsp, otherwise try JSONPath.sh)
|
||||
-Q quick check tool using trivial input (def: do not)
|
||||
-Q quick check tool using trivial input and exit, ignore file.json and pattern (def: do not)
|
||||
|
||||
file.json JSON file to read, - ==> read stdin
|
||||
pattern Xpath for JSON query pattern (def: $PATTERN}
|
||||
file.json JSON file to read, - ==> read stdin (ignored if -Q)
|
||||
pattern Xpath for JSON query pattern (def: $PATTERN) (ignored if -Q)
|
||||
|
||||
Exit codes:
|
||||
0 all OK
|
||||
1 JSONPath.sh exited non-zero
|
||||
1 some internal tool exited non-zero
|
||||
2 -h and help string printed or -V and version string printed
|
||||
3 command line error
|
||||
4 bash version is too old
|
||||
@@ -265,17 +284,30 @@ if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[5]: argument count: $#" 1>&2
|
||||
fi
|
||||
case "$#" in
|
||||
0) if [[ -z $QUICK_CHECK ]]; then
|
||||
echo "$0: ERROR: 0 args allowed only with -Q" 1>&2
|
||||
echo "$USAGE" 1>&2
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
1) JSON_FILE="$1"
|
||||
;;
|
||||
2) JSON_FILE="$1"
|
||||
PATTERN="$2"
|
||||
;;
|
||||
*) echo "$0: ERROR: expected i or 2 args, found: $#" 1>&2
|
||||
*) echo "$0: ERROR: expected 1 or 2 args, found: $#" 1>&2
|
||||
echo "$USAGE" 1>&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
#
|
||||
# -Q ignores ignore file.json and pattern
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
JSON_FILE=""
|
||||
PATTERN=""
|
||||
fi
|
||||
#
|
||||
if [[ $JSON_FILE == "-" ]]; then
|
||||
JSON_FILE=""
|
||||
fi
|
||||
@@ -350,83 +382,6 @@ fi
|
||||
export BIN_DIR="bin"
|
||||
|
||||
|
||||
# validate the XPath for JSON tool
|
||||
#
|
||||
case "$XPATHJSON_USE" in
|
||||
|
||||
# case: we will use JSONPath.sh
|
||||
#
|
||||
JSONPath.sh)
|
||||
|
||||
# try JSONPath.sh
|
||||
#
|
||||
if [[ -z $JSONPATH_SH || ! -x $JSONPATH_SH ]]; then
|
||||
echo "$0: ERROR: JSONPath.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify JSONPath.sh supports -S -4 -p
|
||||
if ! "$JSONPATH_SH" -S -4 -p >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: JSONPath.sh tool does not support -S -4 -p: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we will use jsp
|
||||
#
|
||||
jsp)
|
||||
|
||||
# try jsp
|
||||
#
|
||||
if [[ -z $JSP_TOOL || ! -x $JSP_TOOL ]]; then
|
||||
echo "$0: ERROR: jsp.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify jsp
|
||||
if ! "$JSP_TOOL" --indent 4 --format --no-color >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: jsp tool does not support --indent 4 --format --no-color: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: you might need to update and reinstall jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: or you might try to obtain and install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we do not have an XPath for JSON tool
|
||||
#
|
||||
*)
|
||||
echo "$0: ERROR: cannot find an XPath JSON tool to use" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# print running info if verbose
|
||||
#
|
||||
# If -v 3 or higher, print exported variables in order that they were exported.
|
||||
@@ -484,6 +439,97 @@ if [[ -n $DO_NOT_PROCESS ]]; then
|
||||
fi
|
||||
|
||||
|
||||
# validate the XPath for JSON tool
|
||||
#
|
||||
case "$XPATHJSON_USE" in
|
||||
|
||||
# case: we will use JSONPath.sh
|
||||
#
|
||||
JSONPath.sh)
|
||||
|
||||
# try JSONPath.sh
|
||||
#
|
||||
if [[ -z $JSONPATH_SH || ! -x $JSONPATH_SH ]]; then
|
||||
echo "$0: ERROR: JSONPath.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify JSONPath.sh supports -S -4
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: about to: $JSONPATH_SH -S -4 >/dev/null 2>&1 <<< $FIZZBIN_JSON" 1>&2
|
||||
fi
|
||||
if ! "$JSONPATH_SH" -S -4 >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: JSONPath.sh tool does not support -S -4 $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: passed quick check: $JSONPATH_SH" 1>&2
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we will use jsp
|
||||
#
|
||||
jsp)
|
||||
|
||||
# try jsp
|
||||
#
|
||||
if [[ -z $JSP_TOOL || ! -x $JSP_TOOL ]]; then
|
||||
echo "$0: ERROR: jsp.sh tool is not installed, is not executable, or not in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: obtain JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi
|
||||
|
||||
# case: -Q - perform quick check
|
||||
#
|
||||
if [[ -n $QUICK_CHECK ]]; then
|
||||
# verify jsp
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: about to: $JSP_TOOL --indent 4 --format --no-color >/dev/null 2>&1 <<< $FIZZBIN_JSON" 1>&2
|
||||
fi
|
||||
if ! "$JSP_TOOL" --indent 4 --format --no-color >/dev/null 2>&1; then
|
||||
echo "$0: ERROR: jsp tool does not support --indent 4 --format --no-color: $FIZZBIN_JSON" 1>&2
|
||||
echo "$0: notice: you might need to update and reinstall jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: or you might try to obtain and install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
fi <<< "$FIZZBIN_JSON"
|
||||
if [[ $V_FLAG -ge 1 ]]; then
|
||||
echo "$0: debug[1]: passed quick check: $JSP_TOOL" 1>&2
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
|
||||
# case: we do not have an XPath for JSON tool
|
||||
#
|
||||
*)
|
||||
echo "$0: ERROR: cannot find an XPath JSON tool to use" 1>&2
|
||||
echo "$0: notice: we recommend you obtain and install jsp from: $JSP_REPO" 1>&2
|
||||
echo "$0: notice: or obtain jsp via \"pipx install jsp\" and placing ~/.local/bin in \$PATH" 1>&2
|
||||
echo "$0: notice: otherwise install JSONPath.sh from: $JSONPATH_REPO" 1>&2
|
||||
echo "$0: notice: if possible install jsp instead of JSONPath.sh as jsp is faster" 1>&2
|
||||
exit 5
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# -n means we have nothing to do
|
||||
#
|
||||
if [[ -n $NOOP ]]; then
|
||||
|
||||
+4
-4
@@ -15294,15 +15294,15 @@
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.ioccc.org/bin/jfmt-wrapper.sh</loc>
|
||||
<lastmod>2025-04-21T07:52:21+00:00</lastmod>
|
||||
<lastmod>2025-05-04T21:37:04+00:00</lastmod>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.ioccc.org/bin/jprint-wrapper.sh</loc>
|
||||
<lastmod>2025-04-21T07:52:00+00:00</lastmod>
|
||||
<lastmod>2025-05-04T21:36:06+00:00</lastmod>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.ioccc.org/bin/jval-wrapper.sh</loc>
|
||||
<lastmod>2025-04-21T08:26:44+00:00</lastmod>
|
||||
<lastmod>2025-05-04T21:35:57+00:00</lastmod>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.ioccc.org/bin/manifest.csv.entry.awk</loc>
|
||||
@@ -15598,7 +15598,7 @@
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.ioccc.org/status.html</loc>
|
||||
<lastmod>2025-05-02T23:34:01+00:00</lastmod>
|
||||
<lastmod>2025-05-04T22:27:14+00:00</lastmod>
|
||||
</url>
|
||||
<url>
|
||||
<loc>https://www.ioccc.org/status.json</loc>
|
||||
|
||||
Reference in new issue
Block a user