Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#4257 closed Bug (invalid)

JSON parser fails to parse comments

Reported by: Trina Owned by:
Priority: Normal Milestone: None Set
Component: Daemon Version: 2.31
Severity: Normal Keywords:


According to the wiki: "json was chosen because it's mostly human-readable and -writable"

But part of a readable configuration is to add comments for documentation purposes. The transmission JSON parser fails if the settings file contains any comments.

I would suggest looking at using the [ yajl] C library. It's a popular parser used by many projects.

Change History (4)

comment:1 Changed 11 years ago by jordan

  • Resolution set to invalid
  • Status changed from new to closed

The grammar on doesn't define any comments at all, so it's not surprising that JSON_parser.c doesn't handle them.

yajl looks like a good library, but if it allows comments then it's apparently not following the spec.

comment:2 Changed 11 years ago by Trina

In Douglas Crockford's [ own words]:

JSON does not have comments. A JSON encoder MUST NOT output comments.
A JSON decoder MAY accept and ignore comments.

And many JSON decoders do indeed parse comments fine.

comment:3 Changed 11 years ago by jordan

I'm not going to switch parsers over this issue.

You may want to request this feature upstream to the JSON_parser.c maintainer.

comment:4 Changed 11 years ago by howl

A JSON parser based on's JSON_checker code.

Copyright (c) 2007-2010 Jean Gressmann (jean@…).

For license information, see JSON_parser.c.

JSON parser features:

  • arbitrary levels of JSON object/array nesting,
  • C-style comments,
  • UTF-16 & escape sequence (\uXXXX) decoding to UTF-8.
  • Manual processing of floating point values.

The parser processes UTF-8 encoded JSON only. JSON object keys and JSON strings are returned as UTF-8 encoded C strings.

In fact JSON_parser.c seems to support comments, watching a sample file at at least multiline (/*...*/) don't know if single line (/ /...) are parsed right.

The default is to not allow comments, so allow_comments needs to be set to a non-zero value.

Last edited 11 years ago by howl (previous) (diff)
Note: See TracTickets for help on using tickets.