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>
# 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"`"
}
}
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() {