Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON decoding fails on trailing comma #16945

Closed
kvark opened this Issue Sep 2, 2014 · 8 comments

Comments

Projects
None yet
5 participants
@kvark
Copy link
Contributor

kvark commented Sep 2, 2014

extern crate debug;
extern crate serialize;
use serialize::json;

#[deriving(Decodable)]
struct Spec {
    pub schema: String,
}

static INPUT: &'static str = "
{
    \"schema\" : \"xxx\",
}
";

fn main() {
    println!("{:?}", json::decode::<Spec>(INPUT));
}

Gives me:

task '

' failed at 'assertion failed: !self.is_empty()', /build/rust-git/src/rust/src/libserialize/json.rs:1206

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 2, 2014

That's because JSON doesn't allow for a trailing comma, I'd imagine.

@mahkoh

This comment has been minimized.

Copy link
Contributor

mahkoh commented Sep 2, 2014

The standard specification is clearly wrong here and the decoder should accept trailing commas.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 2, 2014

Well, that's not how standards work.

@mahkoh

This comment has been minimized.

Copy link
Contributor

mahkoh commented Sep 2, 2014

Not sure what you mean by that. I'm not saying that the encoder should produce trailing commas.

@mahkoh

This comment has been minimized.

Copy link
Contributor

mahkoh commented Sep 2, 2014

There is some precedence for not allowing trailing commas: Go, Chromium, and Firefox reject such json. The specification is still wrong for not allowing them and I see no reason not to parse them.

@kvark

This comment has been minimized.

Copy link
Contributor Author

kvark commented Sep 2, 2014

@steveklabnik sad but true. Please feel free to close the issue then.

@kvark

This comment has been minimized.

Copy link
Contributor Author

kvark commented Sep 2, 2014

We could, however, have a better error message.

@lucy

This comment has been minimized.

Copy link
Contributor

lucy commented Sep 2, 2014

It shouldn't fail, since it returns a Result containing possible parse errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.