• dan@upvote.au
    link
    fedilink
    arrow-up
    54
    arrow-down
    2
    ·
    1 year ago

    Friendly reminder if you prefer dealing with JSON - YAML is a superset of JSON, so any valid JSON is also valid YAML.

    • magic_lobster_party@kbin.social
      link
      fedilink
      arrow-up
      52
      ·
      1 year ago

      That’s more of a weakness of yaml. There’s so many ways to specify the exact same thing. Not exactly what you need for configuration files maintained by multiple people. It easily becomes an big incoherent mess.

      In JSON the default way is the only way. Nice and coherent.

      • dan@upvote.au
        link
        fedilink
        arrow-up
        29
        arrow-down
        1
        ·
        edit-2
        1 year ago

        I agree that YAML is painful and it really seems like it’s had a lot of feature creep.

        JSON is painful in its own way too, though. There’s a lot of syntax noise from things like braces, quotation marks, etc, so it’s easy to make a mistake. Regular JSON doesn’t allow trailing commas.

        YAML tried to solve some of that, and did succeed in some ways, but introduced its own issues.

        TOML seems great to me, but maybe it has its own issues. TOML actually has defined data formats for things like dates (both offset and local) and times, which is missing from both JSON and YAML so every app ends up doing it its own way.

        • XTornado@lemmy.ml
          link
          fedilink
          arrow-up
          11
          ·
          1 year ago

          One big thing of JSON I hate is that sometimes is used for config files or similar and it doesn’t supports comments which sucks.

          • rambaroo@lemmy.world
            link
            fedilink
            arrow-up
            7
            ·
            edit-2
            1 year ago

            JSONC does support comments but it wouldn’t be interoperable with anything expecting pure JSON. But still useful for local configs.

    • Terrasque@infosec.pub
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      Found out the hard way that no, it’s not… there are a few valid json files that most yaml parsers choke on

    • TwistedTurtle@monero.town
      link
      fedilink
      arrow-up
      6
      ·
      1 year ago

      It’s been satisfying watching my configuration.yaml file shrink over the years as more and more things get handled by the UI.

    • EmergMemeHologram@startrek.website
      link
      fedilink
      arrow-up
      59
      arrow-down
      2
      ·
      edit-2
      1 year ago

      Not always, but the second you use anchor/references you have sold your soul in a Faustian bargain of convenience.

      On the alignment chart of data/markup formats:

      • lawful good: JSON
      • lawful neutral: TOML
      • lawful evil: XML
      • neutral good: reStructuredText
      • true neutral: HTML
      • neutral evil: LaTeX
      • chaotic good: YAML
      • chaotic neutral: Markdown
      • chaotic evil: xlsx/csv
      • morrowind@lemmy.ml
        link
        fedilink
        arrow-up
        23
        arrow-down
        1
        ·
        1 year ago

        Nah this chart needs fixing. Raw html is not neutral. And how is html neutral but xml evil. And who is writing restructured text outside of python?

        • MotoAsh@lemmy.world
          link
          fedilink
          arrow-up
          4
          ·
          1 year ago

          Also where’s regex? Though that’s so troublesome because it’s a process encoded in a string, not really a structure with debatably obnoxious syntax… hmm

          • lud@lemm.ee
            link
            fedilink
            arrow-up
            2
            ·
            1 year ago

            Because regex isn’t a language used way to store or view data. It’s just a quick way to find, and potentially replace text.

      • uid0gid0@lemmy.world
        link
        fedilink
        arrow-up
        20
        ·
        1 year ago

        I honestly think that JSON and YAML should be swapped due to YAML’s strict indentation rules whereas you can just pack an entire JSON object on one line.

        • Socsa@sh.itjust.works
          link
          fedilink
          arrow-up
          9
          ·
          1 year ago

          Also JSON has no comments. Which is great for me because I hate documenting my work, but it’s still annoying.

            • sloppy_diffuser@sh.itjust.works
              link
              fedilink
              English
              arrow-up
              1
              ·
              1 year ago

              I just learned yesterday you can do this, lol. You can use “//”: ‘’ once at the root level of a package.json file.

              Had to put an override to block a dependency of a dependency from installing (@types/* stubs when the package now has native type defs that conflicted with the no longer maintained stubs).

              I put in a comment as to why its there.

        • magic_lobster_party@kbin.social
          link
          fedilink
          arrow-up
          6
          ·
          1 year ago

          I think yaml’s need for indentation alone makes it chaotic evil. I’ve seen so many people struggle with the indentation than they really need to it’s not fun. Especially problematic with large configuration files.

          JSON is easy to unpack with tools like jq or whatever.

          • EmergMemeHologram@startrek.website
            link
            fedilink
            arrow-up
            3
            ·
            1 year ago

            There are 6 different combinations of “interpret multiline whitespace” character patterns. There are three types of single-line strings, and if you use “Yes” or “No” the data gets type cast.

            Yaml is chaotic.

            • uid0gid0@lemmy.world
              link
              fedilink
              arrow-up
              3
              ·
              1 year ago

              Just because there are a lot of rules doesn’t make something chaotic in this system. The lawful-chaotic axis is a spectrum of how much of a stickler for the rules you are. YAML’s “one whitespace out of place and your whole config is fucked” attitude puts it squarely into lawful territory. JSON by contrast gives no shits about your file structure as long as your curly braces match.

        • peopleproblems@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          1 year ago

          Oh this is a good point - the syntax error on line one has ruined several productive days.

          Of course the tool would happily prettify it for me, but it has to be valid json. Which I think would make it more enjoyable if it said in that message “Good luck, we’re counting on you.”

    • marcos@lemmy.world
      link
      fedilink
      arrow-up
      37
      arrow-down
      1
      ·
      1 year ago

      Yes, a bit. But that’s not the problem.

      The problem is that the current fashion of devops is done through piles and piles of badly defined YAML. If it used any other configuration language, it would be just as bad.

      • Michal@programming.dev
        link
        fedilink
        arrow-up
        16
        arrow-down
        1
        ·
        1 year ago

        How’s it annoying? It’s easier to edit by hand than json as it allows for comments and there’s no trailing comma errors. I prefer it any day over json.

    • MagicShel@programming.dev
      link
      fedilink
      arrow-up
      8
      ·
      1 year ago

      There are plugins that go back and forth between JSON and YAML so as you might expect it’s similar. Unlike JSON, spacing has semantic meaning, which can be a little annoying, especially when cutting and pasting. It’s nice in that configs aren’t cluttered up with open and close braces. It could be annoying AF if you’re a tabs instead of spaces person but idk because I’m a spaces person.

      I like YAML for config over .config files but it’s not a big deal either way. It just encourages better organization of settings because the hierarchical structure demands it while .config let’s you just drop a setting anywhere in the file. But it’s valid to have the opposite preference for the exact same reasons.

    • unalivejoy@lemm.ee
      link
      fedilink
      English
      arrow-up
      6
      ·
      1 year ago

      I’ll answer your question with a question. Why does YAML support sexagesimal? (that’s base 60)

      ports:
      - 22:22
      

      Becomes

      {
        "ports": [1342]
      }
    • Tuna Casserole@programming.dev
      link
      fedilink
      arrow-up
      5
      arrow-down
      1
      ·
      1 year ago

      not at all. it’s used for configuration and stuff. having a lot of it can be a real bummer depending on the context. like a puppet config or perhaps a super weird docker compose setup. I’ve never heard anyone complain about the markup though. it’s like blaming json for a crap api or something or idk blaming the coffee cup for burnt coffee 🤷

      • MotoAsh@lemmy.world
        link
        fedilink
        arrow-up
        8
        ·
        1 year ago

        It’s just another structured data format. It’s used for a lot more than config. It’s also how you define commands and etc for Ansible. Like how a Maven project is defined in XML or a NodeJS package has its JSON.

        Sure they’re still “just” data formats on their own, but what they’re used for is genuinely just as important as what it is. I really doubt XML would’ve held on like it has without HTML being the web.

      • sndrtj@feddit.nl
        link
        fedilink
        arrow-up
        3
        ·
        1 year ago

        For some little config it’s fine, but it’s horrible when used when you have thousands upon thousands of lines of it. Lots of DevOps tools tend to use it like a fully-blown turing-complete programming language, and each has a different DSL of doing variables, loops etc. And that becomes an abomination.

    • learningduck@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      I learned the hard way that no is false in yaml. Took us a while to realize why our app failed to start in Norway. Too many ways to do something.