12+ Years of App Development
Everything from a single source
50+ Successful App Projects

Blog

Changing a File's Encoding with iconv

In one of my current app projects, a Windows application creates the data that should be displayed in the app in JSON format. When umlauts and special characters started displaying incorrectly inside the app, it quickly became clear that the source file was not encoded as UTF-8 as expected.

For an upcoming presentation of the current development progress, the file had to be converted to UTF-8. On Unix-like systems, iconv is a tool that was previously unknown to me and handles exactly this task perfectly.

You can do this with iconv -f old_encoding -t new_encoding sourcefile > targetfile. My source file came from a Windows system, so I assumed it was encoded as Windows-1252. iconv -f Windows-1252 -t UTF-8 demo.json > demoUTF8.json produces a file encoded in UTF-8.

You can display a list of supported encodings with iconv -l. At gnu.org there is a good overview of the parameters and their meaning.

A really helpful tool when you need to convert encodings quickly.

Update: iconv is only available after installing the Xcode tools.

Sebastian Seidel

Sebastian Seidel

As a mobile enthusiast and managing director of Cayas Software GmbH, it is very important to me to support my team and our customers in discovering new potential and growing together. Here I mainly write about the development of Android and iOS apps with Xamarin and .NET MAUI.

Related Articles