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

Escaped strings in JSON #16

Closed
shreyasbharath opened this issue Sep 2, 2014 · 3 comments
Closed

Escaped strings in JSON #16

shreyasbharath opened this issue Sep 2, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@shreyasbharath
Copy link

Hello again,

Say if we were to parse JSON that looked like this -

{
    "message": "\"Hello there\""
}

When we read it out like so -

JsonObject root = parser->parse( json );
const char *message = root["message"];
// Shouldn't we be getting the unescaped form here?

I noticed that we still get the escaped form. Perhaps this is a bug in Jsmn?

@shreyasbharath shreyasbharath changed the title Unescape strings Escaped strings in JSON Sep 2, 2014
@bblanchon
Copy link
Owner

I do agree there is something wrong here: you expected message to be "Hello there" but it's actually \"Hello there\"
The backslashes should not be present in the output.

But there is a good reason for that :bowtie:
As it's a library designed for low-end embedded system, I originally decided that the library would not be allowed to move bytes in the string.
I thought that the performance penality wasn't worth it and that nobody would ever see it.

Turns out I was wrong twice.
First you proved me that somebody did see the bug.
Second, I now think that the cost of moving is acceptable, it’s just O(1) after all.

That's going to be in 3.4.
Thanks again 😉

@bblanchon bblanchon added this to the 3.4 milestone Sep 2, 2014
@bblanchon bblanchon added the bug label Sep 2, 2014
@bblanchon bblanchon self-assigned this Sep 2, 2014
@shreyasbharath
Copy link
Author

Awesome :)

@bblanchon
Copy link
Owner

OK, it's fixed in 3.4.

The code size increased by 118 bytes on 8-bit AVR.
I think that's acceptable.

Sorry it took so long for such a small fix.

Repository owner locked and limited conversation to collaborators Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants