Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorPhilip Prindeville <philipp@redfish-solutions.com>2023-04-14 21:37:05 +0300
committerAlexander Couzens <lynxis@fe80.eu>2023-04-15 16:04:19 +0300
commit6fc29d1c429240a9afb71c22aa161b066502f3ed (patch)
tree3f1fb3ad1c43b18070ea56131106f3144015248f /sh
parentef5e8e38bd38f26e2da2f6f0a2d720468c935280 (diff)
jshn.sh: Add pretty-printing to json_dump
If a JSON file might be read by a human, say for debugging, it could be useful to pretty-print it. We do this in places by calling "json_dump -i" but it shouldn't be necessary to know the arguments to "jshn" (and indeed, that's not portable if we retool the underlying implementation). Conversely output that's ephemeral doesn't need to be pretty (say being piped as input to another command). Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
Diffstat (limited to 'sh')
-rw-r--r--sh/jshn.sh12
1 files changed, 11 insertions, 1 deletions
diff --git a/sh/jshn.sh b/sh/jshn.sh
index c973692..1d30557 100644
--- a/sh/jshn.sh
+++ b/sh/jshn.sh
@@ -199,6 +199,16 @@ json_add_fields() {
# functions read access to json variables
+json_compact() {
+ JSON_NONEWLINE=1
+ JSON_INDENT=
+}
+
+json_pretty() {
+ JSON_NONEWLINE=
+ JSON_INDENT=1
+}
+
json_load() {
eval "`jshn -r "$1"`"
}
@@ -208,7 +218,7 @@ json_load_file() {
}
json_dump() {
- jshn "$@" ${JSON_PREFIX:+-p "$JSON_PREFIX"} -w
+ jshn "$@" ${JSON_PREFIX:+-p "$JSON_PREFIX"} ${JSON_NONEWLINE:+-n} ${JSON_INDENT:+-i} -w
}
json_get_type() {