-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Parse method doesn't handle newlines. #659
Comments
Outside of a quoted string, newlines cause the parser to fail. {"a":1 , "b": 2\n
"c": 3\n
} string s = "{\"a\":\"b\",\n \"c\":\"d\"}"; when passed in as a string to json::parse(s) |
You're missing a comma between 2 and "c" in the first. The second isn't valid C++. What is the actual code? |
The second example I did actually type in backslashes before each double quote!
The actual code reads a JSON file (pretty-printed) into a string and passes
the string to the parse method.
…On Tue, Jul 18, 2017 at 4:58 PM gregmarr ***@***.***> wrote:
You're missing a comma between 2 and "c" in the first. The second isn't
valid C++. What is the actual code?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#659 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABukbHP4X1zydO6hjoT5ZpL86sEJBf0vks5sPUadgaJpZM4Ob0kF>
.
|
Have you validated the json file? What is the error message? |
The document in the file was very simple, but how can I get an error message from the parser? Doesn't the parse method just return a json document? |
If there is a parse error, |
@jaslo Any news on this? |
I wrote a work-around to replace all the newlines (after I read the file
into a big char array) with spaces -- none of the newlines are in JSON
strings in the file I'm reading! So it's now working for me. But it's 100%
reproducible. I can work on getting you the error message if you really
need that.
…On Thu, Jul 20, 2017 at 3:43 AM, Niels Lohmann ***@***.***> wrote:
@jaslo <https://github.com/jaslo> Any news on this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#659 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABukbAbpnes1jTkDFEYZsAnlZR4J09v8ks5sPy9LgaJpZM4Ob0kF>
.
|
I really need to see the example. So far, I cannot reproduce any issues with newlines in the parser. |
(If your example is reproducible and you cannot share the JSON file, maybe you can provide a smaller version?) |
ok, I will post today. |
I could not repro with a standalone app in windows, but this bug was reported on mac. I will try the test app on mac. |
That sounds like a line ending issue. If this file was written on Windows, it might have cr/nl pairs, which causes it to choke on mac. |
Could not repro on mac either in my standalone test, with either type of line endings. I'm going to have to get the JSON file from the guy who reported the bug to me. He edited the file with "Power JSON" and then it started failing. |
@jaslo That would be great. |
@jaslo Any news? |
Got the "beautified" file and it seemed to parse fine. So...not a problem.
…On Mon, Jul 24, 2017 at 11:57 PM, Niels Lohmann ***@***.***> wrote:
@jaslo <https://github.com/jaslo> Any news?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#659 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABukbHFvUeKYIQ0c7f7TvMY-JWopECUHks5sRZHbgaJpZM4Ob0kF>
.
|
Got the "bad file" and could not repro. |
Thanks for checking back! |
Hi, I'd like to continue this conversation. I wanted to put an SDP (https://tools.ietf.org/html/rfc4566) into a JSON variable inside a JSON string. Unfortunately the parser stumbles upon the newlines (regardless if \r\n 0x0D0A or \n 0x0A only) with a parse_error. Here is a three liner with which I can reproduce it on VS2017: int main() Shouldn't the "\n" or even "\r\n" be legal? |
Sorry for the noise, I got it. For completenes sake: int main() |
Didn't take the second backslash. Don't know how this works on this website. |
@aholzinger Use code blocks with triple backticks, see https://help.github.com/en/articles/basic-writing-and-formatting-syntax#quoting-code, to post code. |
In .dump() I got escaped new line. But if I do
This is bug? |
JSON strings containing newlines don't parse correctly with the ::parse method!
The text was updated successfully, but these errors were encountered: