#! /bin/sh
#
# Sort the { objects } in a single json array, stdin to stdout
# See qa/1773 for an example of usage.
#
# Copyright (C) 2020 Red Hat.
#
pmjson -n | $PCP_AWK_PROG '
/^\[/ { print "1["; next }
/^\]/ { print "3]"; next }
$1 == "{" { c=""; next }
$1 == "}" || $1 == "}," { printf("2{ %s %s\n", c, $1); next }
{ c=c " " $0 }' | LC_COLLATE=POSIX sort -n | sed -e 's/^[1-3]//' | pmjson -n
