Zulip Chat Archive

Stream: metaprogramming / tactics

Topic: json strings with newlines


Alex J. Best (Nov 30 2022 at 21:20):

Does anyone have any idea why the following breaks,

import data.json

#eval json.parse "hi\n"
#eval json.parse "{\"hi\":\"ho\n\"}"

or better yet how easy it would be to fix?
I believe this is valid JSON, but not accepted by lean.
@Eric Wieser @Edward Ayers perhaps?

Eric Wieser (Nov 30 2022 at 21:20):

Those both look like invalid json to me

Alex J. Best (Nov 30 2022 at 21:22):

I asked https://jsonlint.com/ and it thought it was fine. to be clear the escaping is just for lean, surely a string in json can have a line break in?

Alex J. Best (Nov 30 2022 at 21:22):

Ah but maybe json demands they are escaped

Eric Wieser (Nov 30 2022 at 21:23):

The second would be valid with \\n

Alex J. Best (Nov 30 2022 at 21:25):

Ok all is well then I guess!

Trebor Huang (Dec 01 2022 at 05:49):

Mandatory xkcd: https://xkcd.com/1638/


Last updated: Dec 20 2023 at 11:08 UTC