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


Comments are parsed as JValue-strings


using(var textReader = new StreamReader(stream))
using(var jsonReader = new JsonTextReader(textReader))
    return JToken.ReadFrom(jsonReader);
If the JSON file starts with a comment then a single JValue containing the comment as "string" is returned. If there are comments inside arrays then they are also returned as JValue strings. Looking at the source, JToken.ReadFrom has no handling of comments, so thats probably broken.

Workaround is to strip comments, e.g. by subclassing JsonTextReader as below, but it'd be better if the bug could be fixed.
class FixComments: JsonTextReader
    public FixComments(StreamReader reader)
        : base(reader) { }

    public override bool Read()
                return false;
        while(TokenType == JsonToken.Comment);

        return true;
Closed Apr 26, 2014 at 2:22 PM by JamesNK
Check for the starting comment and read past it if necessary


Auxilium wrote Mar 12, 2014 at 12:33 PM

Other side of problem is also that in all other cases, comments are stripped without an option to keep them.

wrote Mar 12, 2014 at 12:34 PM

Zarat wrote Mar 12, 2014 at 6:47 PM

Yeah, I agree with that, though personally I have no requirement of processing/preserving comments in Json-to-Linq. My workaround of stripping comments is just to get files with comments working at all, because right now you can't even see the difference between an array with strings and an array which happened to have a comment somewhere.

Unfortunately this project looks kinda dead, without any live mailing list or anything, and nobody is looking at the issues reported here or on the official git repository for over a month.

Auxilium wrote Mar 14, 2014 at 10:36 AM

Well, at least we have source opened, I've edited it a little for my purpose (as there was already almost everything ready for that).
I hope it's not dead though, it's a great framework!

Maybe i'll fill a pull request, though need to test it all first.

wrote Apr 26, 2014 at 2:22 PM