Skip to content

Proposal: Switch from JSON to YAML for Config Files #68

@galligan

Description

@galligan

Update from @mikker:

This is a great suggestion. If anyone is up for it: We should look for .json, if it doesn't exist look for .yaml or .yml. If they don't exists either, create default json like now.

JSON and Yaml should have same schema and resolve to the same in-memory object(s).


Hey there @mikker! 👋 First off, loving Leader Key. I was hacking something like it together by way of AeroSpace binding modes, but this is way more purpose-built and slick. I wanted to suggest something that could make the config experience even better: switching from JSON to YAML for configuration files.

Why YAML? 🤔

JSON works fine, but YAML (which is a superset of JSON) really shines when it comes to human readability while maintaining all the machine-readable benefits. It's also a lot more concise, which could help if loading up configs into AI tools for help (fewer tokens used).

Plus, it's battle tested: a bunch of projects like Home Assistant, Docker, and others use YAML for their configs.

Here's a quick comparison using a snippet from a Leader Key config in JSON and the same in YAML:

JSON (Current)

  • 748 characters
  • 38 lines
{
  "type": "group",
  "actions": [
    {
      "type": "group",
      "label": "Open",
      "key": "o",
      "actions": [
        {
          "key": "m",
          "label": "Music",
          "type": "group",
          "actions": [
            {
              "type": "application",
              "value": "/Applications/Spotify.app",
              "label": "",
              "key": "s"
            }
          ]
        },
        {
          "key": "b",
          "label": "Browser",
          "type": "group",
          "actions": [
            {
              "type": "application",
              "value": "/Applications/Safari.app",
              "label": "",
              "key": "s"
            }
          ]
        }
      ]
    }
  ]
}

YAML (Proposed)

  • 411 characters (near 2:1 reduction)
  • 22 lines
type: group
actions:
  - key: o
    type: group
    label: Open
    actions:
      - key: m
        type: group
        label: Music
        actions:
          - key: s
            type: application
            value: /Applications/Spotify.app
      - key: b
        type: group
        label: Browser
        actions:
          - key: s
            type: application
            value: /Applications/Safari.app

Benefits 🌟

  1. Cleaner Visual Hierarchy

    • YAML uses indentation to show structure, making it super easy to scan and understand the config at a glance
    • No more hunting for matching braces or commas!
    • Hyphens denote new list items, making it easier to see the structure of the config
  2. Massive Character Reduction

    • Removes unnecessary quotes, braces, and commas
    • Early testing shows about a 2:1 reduction in file size (great for sharing configs or using with AI tools!)
    • Less typing = fewer chances for syntax errors
  3. Built-in Comments

    type: group
    actions:
      # Quick access to music apps
      - type: group
        label: Music
        key: m
  4. Simpler Special Character Handling

    # In JSON:
    { "key": "\\", "type": "application" }
    
    # In YAML:
    key: \\ # Backslash with simple comment
    type: application

Implementation Notes 🛠

  • YAML is a superset of JSON, so migration would be straightforward
  • Most programming languages have mature YAML parsers
    • Consider using Yams for a Swift YAML parser.
  • Could maintain backward compatibility by supporting both formats initially

What do you think? Would love to hear your thoughts on this!

tl;dr

YAML would make configs more readable, reduce file size by ~50%, and add useful features like comments while maintaining all the functionality we have now. It's a win-win! 🎉

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions