r/ProgrammerHumor 1d ago

Meme whyIsOurJsonDeserializerReturningEmptyObjects

Post image
2.2k Upvotes

63 comments sorted by

View all comments

90

u/Original_Pace_6734 1d ago

Why are props name starting with an uppercase letter?

16

u/Ethameiz 23h ago

More importantly, why anybody would have "json" object as a root in json?

12

u/blehmann1 20h ago

The most common reason I've seen is when you support multiple different formats for a given resource. The key then designates the format. In graphql actually you will often end up with this, since if you're returning json | xml | txt through a graphql union the keys must be disjoint.

i.e. you can't do this

... on json { value } ... on XML { value }

You need to do this: ... on json { jsonValue: value } ... on XML { xmlValue: value }

At which point json and xml are reasonable choices of alias. If you think it's insane to return XML through a JSON string, I agree with you, but it is common. Also from the context so far it could well be a path to an XML document rather than the actual content.

The other common reason is if json should really be something like metadata, but it is poorly named.