And I’ll show you YAML

(a continuation of this post)

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

    JSON for serialization all the way. It’s simple and to the point. It does one thing and does it well. There’s little room for annoying surprises. Any JSON can easily be minified and prettified back and forth. If you want it in binary format you can convert it to BSON.

    Yaml is too much of a feature creep. It tries to do way too many things at the same time. There are so many traps to fall into if you’re not cautious enough. The same thing can be written in multitudes of ways.

  • NewPerspective@lemmy.world
    link
    fedilink
    arrow-up
    41
    arrow-down
    1
    ·
    1 year ago

    My problem with yaml is if you truncate it at any random spot, there’s a high likelihood it’s still valid yaml. I don’t like the idea that things can continue without even knowing there’s a problem. The single opening and closing curly braces enclosing a json object is all it takes to at least know you didn’t receive the entire message. Toml has the same issue. I’ll stick with json when it makes sense.

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

        Quite like YAML, XML has too many stuff in it. While a lot of parsers are not standard compliant and safe, if there’s any chance the stuff you include on your code can evolve into a fully featured parser, including it is something to avoid.

        There is this language called KDL that looks interesting.

  • calcopiritus@lemmy.world
    link
    fedilink
    arrow-up
    41
    arrow-down
    2
    ·
    1 year ago

    Serializing? For serializing you probably want performance above all else. I’m saying this without checking any benchmark, but I’m sure yaml is more expensive to parse than other formats where indentation don’t have meaning.

    For human readability: it has to be readable (and writeable) by all humans. I know (a lot of people) that dislike yaml, toml and XML. I don’t know of a single person that struggles to read/write json, there is a clear winner.

    • DrM@feddit.de
      link
      fedilink
      arrow-up
      20
      ·
      1 year ago

      JSON would be perfect if it allowed for comments. But it doesn’t and that alone is enough for me to prefer YAML over JSON. Yes, JSON is understandable without any learning curve, but having a learning curve is not always bad. YAML provides a major benefit that is worth the learning curve and doesn’t have the issues that XML has (which is that there is no way to understand an XML without also having the XSD for it)

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

        Json should also allow for trailing commas. There’s no reason for it not too. It’s annoying having to maintain commas.

      • Kogasa@programming.dev
        link
        fedilink
        arrow-up
        3
        arrow-down
        2
        ·
        1 year ago

        If a comment isn’t part of the semantic content of a JSON object it has no business being there. JSON models data, it’s not markup language for writing config files.

        You can use comments in JSON schema (in a standardized way) when they are semantically relevant: https://json-schema.org/understanding-json-schema/reference/comments

        For the data interchange format, comments aren’t part of the JSON grammar but the option to parse non-JSON values is left open to the implementation. Many implementations do detect (and ignore) comments indicated by e.g. # or //.

        • frezik@midwest.social
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          JSON models data, it’s not markup language for writing config files.

          JavaScript package management promptly said otherwise. JSON is a config format no matter if you like it or not.

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

            I’ve disagreed with JavaScript before, what makes you think I won’t do it again?

            Anyway, anything using JSON as a config language will also certainly use a JSON interpreter that can ignore comments. Sure that’s “implementation specific,” but so is a config file. You wouldn’t use “MyApplication.config.json” outside the context of MyApplication loading its own configuration, so there’s no need for it to be strictly compliant JSON as long as it plays nicely with most text editors.

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

      Serializing isn’t necessarily about performance, or we’d just use protobuf or similar. I agree Json is a great all rounder. Combine with JSON object schema to define sophisticated DSLs that are still readable, plain JSON. TOML is nice as a configuration language, but its main appeal (readability) suffers when applied to complex modeling tasks. XML is quite verbose and maybe takes the “custom DSL” idea a little too far. YAML is a mistake.

    • Blackmist@feddit.uk
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      1
      ·
      1 year ago

      I don’t know why we’re fucking about trying to use text editors to manipulate structured data.

      Yeah, it’s convenient to just be able to use a basic text editor, but we’re not trying to cram it all on a floppy disk here. I’m sure we could have a nice structured data editor somewhere for all those XML, JSON and YAML files we’re supposed to maintain every day.

  • synae[he/him]@lemmy.sdf.org
    link
    fedilink
    English
    arrow-up
    26
    arrow-down
    1
    ·
    1 year ago

    For serializing? I’d probably just go with json.

    For content meant to be written or edited by humans? YAML all day baby

    • Andy@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      1 year ago

      Ever tried NestedText? It’s like basic YAML but everything is a string (types are up to the code that ingests it), and you never ever need to escape a character.

      • synae[he/him]@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        10
        arrow-down
        1
        ·
        1 year ago

        I’ve got too many consumers that I don’t control which dictate their input formats. And to be quite honest, “types are up to the code that ingests it” sounds like a huge negative to me.

        • Andy@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          Ah, well I love that policy (types being in code, not configs). FWIW I sometimes use it as a hand-edited document, with a small type-specifying file, to generate json/yaml/toml for other programs to load.

  • Artyom@lemm.ee
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    edit-2
    1 year ago

    Yaml is a great, human-readible file format. Unless there’s an exclamation point in it, then it is an illegible Eldrich horror.

  • Windex007@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

    Genuinely curious what features OP is looking for, specifically for serialization as per the post, that has resulted in the conclusion being yaml.