Last active
April 27, 2019 16:03
-
-
Save mcenirm/c9599323afa9bd8d718c29317b2ad5b1 to your computer and use it in GitHub Desktop.
Convert camel to snake in jq
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 camel2snake: | |
gsub("(?<x>[A-Z][a-z]+)"; "_"+.x|ascii_downcase)|ltrimstr("_"); |
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
$ jq -n '["camelCase","NerdCaps","encodeURIComponent","java.util.ArrayList"]' | \ | |
jq 'include "camel2snake"; .|map(camel2snake)' | |
[ | |
"camel_case", | |
"nerd_caps", | |
"encodeURI_component", | |
"java.util._array_list" | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment