diff --git a/normalize.jq b/normalize.jq new file mode 100644 index 00000000..a4407c91 --- /dev/null +++ b/normalize.jq @@ -0,0 +1,13 @@ +# Apply f to composite entities recursively using keys[], and to atoms +def sorted_walk(f): + . as $in + | if type == "object" then + reduce keys[] as $key + ( {}; . + { ($key): ($in[$key] | sorted_walk(f)) } ) | f + elif type == "array" then map( sorted_walk(f) ) | f + else f + end; + +def normalize: sorted_walk(if type == "array" then sort else . end); + +normalize