Convert .desktop Entry Files to JSON
Convert Linux .desktop entry files (used for application launchers) to JSON format. Covers Desktop Entry, Actions, and standard freedesktop.org keys.
Common Files
Detailed Explanation
Desktop Entry Files to JSON
Linux desktop entry files (.desktop) follow the INI format as specified by the freedesktop.org Desktop Entry Specification. They define how applications appear in menus and launchers.
Example .desktop File
[Desktop Entry]
Type=Application
Name=Firefox Web Browser
GenericName=Web Browser
Comment=Browse the World Wide Web
Exec=firefox %u
Icon=firefox
Terminal=false
StartupNotify=true
StartupWMClass=firefox
Categories=Network;WebBrowser;
MimeType=text/html;application/xhtml+xml;x-scheme-handler/http;
Actions=new-window;new-private-window;
[Desktop Action new-window]
Name=Open a New Window
Exec=firefox --new-window
[Desktop Action new-private-window]
Name=Open a New Private Window
Exec=firefox --private-window
Generated JSON
{
"Desktop Entry": {
"Type": "Application",
"Name": "Firefox Web Browser",
"GenericName": "Web Browser",
"Comment": "Browse the World Wide Web",
"Exec": "firefox %u",
"Icon": "firefox",
"Terminal": false,
"StartupNotify": true,
"StartupWMClass": "firefox",
"Categories": "Network;WebBrowser;",
"MimeType": "text/html;application/xhtml+xml;x-scheme-handler/http;",
"Actions": "new-window;new-private-window;"
},
"Desktop Action new-window": {
"Name": "Open a New Window",
"Exec": "firefox --new-window"
},
"Desktop Action new-private-window": {
"Name": "Open a New Private Window",
"Exec": "firefox --private-window"
}
}
Desktop Entry Specifics
- Section names with spaces: Sections like
[Desktop Entry]and[Desktop Action new-window]contain spaces, which are preserved as-is in JSON keys - Semicolon-separated lists:
CategoriesandMimeTypeuse semicolons as delimiters. These remain as strings in JSON; your application should split them - Boolean fields:
TerminalandStartupNotifyusetrue/falseand are properly coerced - Exec format codes: Values like
firefox %ucontain freedesktop.org format codes (%u,%F, etc.) that are preserved as literal strings - Localization keys: Desktop files may have localized keys like
Name[ja]=ファイアフォックスwhich are handled as regular keys with bracket notation in the name
Use Case
Building a desktop application manager that reads .desktop files as JSON for a web-based admin interface, allowing system administrators to manage application launchers, edit Exec commands, and configure MIME type associations across managed Linux workstations.