Skip to content

Commit

Permalink
Add normalize function
Browse files Browse the repository at this point in the history
  • Loading branch information
shanev committed Jul 12, 2021
1 parent 92148c0 commit 960c32d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions normalize.jq
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 960c32d

Please sign in to comment.