Skip to content

Instantly share code, notes, and snippets.

@mcenirm
Last active April 27, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcenirm/c9599323afa9bd8d718c29317b2ad5b1 to your computer and use it in GitHub Desktop.
Save mcenirm/c9599323afa9bd8d718c29317b2ad5b1 to your computer and use it in GitHub Desktop.
Convert camel to snake in jq
def camel2snake:
gsub("(?<x>[A-Z][a-z]+)"; "_"+.x|ascii_downcase)|ltrimstr("_");
$ 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