• tgm@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    6 hours ago

    I agree with some of the points made in the article, but I think a reason JSON won it is that it is directly representable in many languages. As the author mentions, JSON makes dictionaries, which has native types in most, if not all, languages I have used and languages like JS/TS and Python have native support for JSON.

    So interpreting a JSON string is easier and doesn’t necessitate a custom type, while allowing for it. Both TS and Python (3) do have static analysis and type checking for JSON, with some limitations.

    The final point I feel the other missed is that JSON and by extension YAML is more concise and therefore more readable, even in a terminal or console where syntax highlighting might not be available. In my experience the speed at which humans kan parse DTOs increase troubleshooting and development.

    That said they do mention several use cases where I agree that XML is a better tool, but I still believe that JSON is the better general purpose tool. If your model for DTOs is tight and well defined XML may well be the better option and JSON does have some significant drawbacks, but not enough that I would start my project out using XML unless I know I will need to compose XML files or enforce strict type checking.

    In my, albeit limited, experience using XML the time saved on type checking DTOs is spent on writing and maintaining serializers and deserializers. Thus the benefit of one tool over the other depends on the use case.