Created
December 18, 2018 21:15
-
-
Save mattdeboard/0b0255469c435517f51c89d7897d3886 to your computer and use it in GitHub Desktop.
Convert snake_case JSON keys in region to camelCase
This file contains hidden or 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
(defun camelcase-keys-in-region (start end) | |
"Change snake_case JSON keys in the region to camelCase. | |
START and END are start/end of region." | |
(interactive "r") | |
(save-restriction (narrow-to-region start end) | |
(goto-char (point-min)) | |
(while (re-search-forward "^ *[a-z0-9_]+:" nil t) | |
(while (re-search-backward "_\\(.\\)" (point-at-bol) t) | |
(replace-match (upcase (match-string 1))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is pretty inefficient (search forward, then backward) because the JSON I'm processing may have values that are also snake_case, so I can't just process all snake-cased words.