Skip to content

Instantly share code, notes, and snippets.

@davidalpert
Created December 10, 2017 20:50
Show Gist options
  • Save davidalpert/3cd6e830c37b2d617bedbeb9fd05a72d to your computer and use it in GitHub Desktop.
Save davidalpert/3cd6e830c37b2d617bedbeb9fd05a72d to your computer and use it in GitHub Desktop.
Sort json by keys and selected vaules
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