This project has moved and is read-only. For the latest updates, please go here.

JSON and comments

Jan 2, 2008 at 6:47 PM
Edited Jan 2, 2008 at 7:07 PM
Browsing through the Json.NET 1.3.1 source code, I’m guessing this code was based on an earlier version of the JSON spec. In particular I note support for /*…*/ style comments. As I understand it, the comment feature got removed from the JSON spec specifically to make it a subset of YAML. I don't know how widely this was discussed in the JSON community, but the YAML community certainly noticed and appreciates it.

YAML, on the other hand, supports shell-style comments # - to end-of-line. That didn't get added to JSON as it's not a subset of JavaScript, but I notice that some of the other JSON reader packages support # comments as an extension:

Based on this history, it appear true JSON doesn't support comments. I suppose supporting either kind of comments one in a JSON de-serializer is not a bad thing providing the construct would otherwise be illegal, though I'll suggest there should probably be a strict-mode which rejects any non-standard constructs. On the other hand, serializing comments (of either style) into a JSON output stream means the result isn't JSON at all.

Does that seem right?
Feb 9, 2008 at 12:23 AM
Yes, I am pretty sure that JSON doesn't support comments.

Json.NET has the ability to read and write them but the standard serializer will never write comments.