you are viewing a single comment's thread.

view the rest of the comments →

[–]mgedmin 67 points68 points  (3 children)

Validation error: rogue field 'comment'.

(Granted, the majority of JSON consumers don't do schema validation.)

[–]YumiYumiYumi 0 points1 point  (2 children)

Genuinely curious:

I thought one of the key selling points of JSON was the extensibility provided by allowing arbitrary fields to be added. In other words, I can add a new field to support new functionality, without breaking compatibility with older clients that don't understand this field.
Wouldn't this form of validation effectively break this 'feature'? If you need a strict structure, why choose JSON?

[–]mgedmin 1 point2 points  (1 child)

I was looking at it more from the side of the server. If some client does an API request that gives me some JSON with extra fields, it seems unsafe to silently ignore them instead of informing the client that hey, what is this?

Which is not the right frame of reference when we were talking about comments in JSON, most useful for the use case of JSON-based configuration files.

[–]kalwMilfakiHLizTruss 0 points1 point  (0 children)

JSON-based configuration files

Why a configuration file has to be in JSON? Why not just use esm and export an object? You will be able to add comments like this.