Bug 15510 – json shouldn't escape forward slash by default

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2016-01-04T04:39:03Z
Last change time
2024-12-13T18:46:18Z
Assigned to
No Owner
Creator
Timothee Cour
Moved to GitHub: dmd#17741 →

Comments

Comment #0 by timothee.cour2 — 2016-01-04T04:39:03Z
void main(){ import std.json; JSONValue v = [ "file": "a/b"]; auto v2=v.toString; assert(v2==`{"file":"a\/b"}`, v2); } It would be nice to have an option (which should be default IMO) to not escape forward slashes. context: http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped https://github.com/esnme/ultrajson/issues/110 QUOTE: The JSON spec says that forward slashes may be escaped or not escaped. Unless there is a compelling reason to escape them it would be preferable to follow the behavior of Python's json module and not escape them.
Comment #1 by andre — 2016-03-17T19:16:38Z
Everywhere I use toString method I also add the replace(`\/`,`/`) because for my use cases the \/ escaping is just wrong. I am not sure whether the default behavior should be changed because this could silently introduce new behaviors in existing programs but there should be definitely a new option "noForwardSlashEncoding" in JSONOptions.
Comment #2 by ttanjo — 2024-03-29T18:45:20Z
Can we close this issue as resolved? Now we can use JSONOptions.doNotEscapeSlashes to change its behavior. - https://dlang.org/phobos/std_json.html#.JSONOptions.doNotEscapeSlashes
Comment #3 by robert.schadek — 2024-12-13T18:46:18Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17741 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB