Proposed patch: allow comments (C style) in Json

61 views
Skip to first unread message

gary...@gmail.com

unread,
Jan 7, 2019, 12:30:58 PM1/7/19
to Jansson users
The attached patch to 2.12 implements C style comment processing inside Json. This feature is enabled by the flag JSON_ALLOW_COMMENTS (for the json_load family functions). The flag  is disabled by default.
It supports both // and /* ... */ comments. Comments can occur anywhere whitespace is permitted. Comments are not preserved, so a json_load followed by a json_dump will strip the comments.

I know the issue of comments in Json is controversial since it is not part of  RFC 4627. Others will argue that comments that are not preserved are worthless.
First, there is virtually no performance impact if you do not enable JSON_ALLOW_COMMENTS. So what's the harm? Many Json libraries out there support comments. For Json  files that are meant to be created and maintained by humans (such as configuration files), comments are essential.

As to RFC conformance, JSON_ENCODE_ANY violates RFC 4627 so there precedence.

The patch impacts jansson.h and load.c only.

If accepted, I would be happy to add a test suite and modify the documentation.
patch.txt

Petri Lehtinen

unread,
Jan 12, 2019, 4:24:12 AM1/12/19
to jansso...@googlegroups.com
Hi.

Requests for comment support have been rejected multiple times during the almost 10 years of Jansson's history due to not being present in either of the JSON RFCs.

Users are encouraged to do their own preprocessing to strip comments before parsing.

Petri
--
--
Jansson users mailing list
jansso...@googlegroups.com
http://groups.google.com/group/jansson-users
---
You received this message because you are subscribed to the Google Groups "Jansson users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jansson-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<patch.txt>

Gonzalo Diethelm

unread,
Aug 20, 2020, 2:47:33 PM8/20/20
to Jansson users
That's a pity. I would also love to have (optional) support for comments and other "relaxed JSON" options. I even created an issue: https://github.com/akheron/jansson/issues/547

Cheers!
Reply all
Reply to author
Forward
0 new messages