Created
December 10, 2017 20:50
-
-
Save davidalpert/3cd6e830c37b2d617bedbeb9fd05a72d to your computer and use it in GitHub Desktop.
Sort json by keys and selected vaules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 extradata_sort_key_for: | |
if type != "object" then . | |
elif has("Name") then .Name | |
elif has("Scope") then .Scope | |
else . | |
end; | |
def normalize: sorted_walk(if type == "array" then sort_by(extradata_sort_key_for) else . end); | |
normalize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment