How to convert string to camel and snake case in Elixir

Article autor
September 9, 2025
How to convert string to camel and snake case in Elixir
Elixir Newsletter
Join Elixir newsletter

Subscribe to receive Elixir news to your inbox every two weeks.

Oops! Something went wrong while submitting the form.
Elixir Newsletter
Expand your skills

Download free e-books, watch expert tech talks, and explore open-source projects. Everything you need to grow as a developer - completely free.

Table of contents

Sooner or later you may need to convert a string in Elixir to a camel or snake case. With Macro module (available in Elixir without extra dependency) it's super easy.

Converting into snake case

> Macro.underscore("ThisWillBeSnakeCase")
"this_will_be_snake_case"

Converting into camel case

> Macro.camelize("this_will_be_camel_case")
"ThisWillBeCamelCase"

Related posts

Dive deeper into this topic with these related posts

No items found.

You might also like

Discover more content from this category

Style spacing between repeated elements in CSS using flex gap

It's a pretty common scenario - you have to place a few elements in equal distances. E.g. unordered list items.

Using Logger.info and Logger.debug in ExUnit tests

By default in the test env, Phoenix doesn't show Logger.debug/Logger.info outputs in the console.

How to check if a set contains exact values with Jest in JS?

TLDR: With jest-extended package you can write: expect([...set]).toIncludeSameMembers([value1, value2]);. If you are looking to a native, but longer solution scroll down a bit.