If you JSON export an association with a url, it will espace the forward slashes like this:
ExportString[ <|"url" -> "http://s2d3.scene1.com/medium/94760712386071_001.jpg"|>,
"JSON"]
How can I get this not to happen?
Don't know if there is a neat solution but here is one approach. Assuming you can mark your urls with URL
:
json = <|"url" -> URL @ "http://s2d3.scene1.com/medium/94760712386071_001.jpg"
, "urlω2" -> URL@"http://wolfram.com"
|>;
FileTemplateApply[#, #2[[1]], "file.json"] & @@
Reap @
ExportString[
json
, "RawJSON"
, "ConversionFunction" -> Function[Sow[First@#]; "``"]
]
FilePrint@"file.json"
Import["file.json", "RawJSON"]
{ "url":"http://s2d3.scene1.com/medium/94760712386071_001.jpg", "urlÏ2":"http://wolfram.com" }
<|"url" -> "http://s2d3.scene1.com/medium/94760712386071_001.jpg", "urlω2" -> "http://wolfram.com"|>
// StringReplace["\\/" -> "/"]
is not an option? $\endgroup$Export
notExportString
and only a few of the fields are URLs (don't want to un-escape all of them). $\endgroup$Export["~/Downloads/tmp.json", ExportString[<|"a" -> "http://a.b/c:de", "b" -> 123, "c" -> <|"url" -> "http://s2d3.scene1.com/medium/94760712386071_001.jpg"|>|>, "JSON"] // StringReplace["\\/" -> "/"], "Text"]
$\endgroup$"String"
not"Text"
to not double encode. It may not matter here but unless I am mistaken, it should be"String"
. $\endgroup$