0

Not sure if I understand the point of writing .json config in a single line like this with both forward and backwards slashes?:

{"name":"zendframework\/zendservice-twitter","description":"OOP wrapper for the Twitter web service","type":"library","keywords":["zf2","twitter"],"homepage":"http:\/\/packages.zendframework.com\/","license":"BSD-3-Clause","autoload":{"psr-0":{"ZendService":"library\/"}},"repositories":[{"type":"composer","url":"http:\/\/packages.zendframework.com\/"}],"require":{"php":">=5.3.3","zendframework\/zend-http":">=2.0.0","zendframework\/zend-uri":">=2.0.0","zendframework\/zend-version":">=2.0.0"},"extra":{"branch-alias":{"dev-master":"2.0.x-dev"}},"version":"2.0.1","dist":{"url":"http:\/\/packages.zendframework.com\/composer\/ZendService_Twitter-2.0.1.zip","type":"zip"}}   
Ryan Eckert
  • 249
  • 3
  • 8

1 Answers1

1

The backslash \ is an escape character, so every time you see \/, the / is being escaped.

The fact that the entire object is written on one line is most likely an artifact of whatever generated the JSON (I'm assuming it was not handwritten).

Brian Driscoll
  • 19,373
  • 3
  • 46
  • 65
  • I believe `/` doesn't need escaping. – John Dvorak Dec 06 '12 at 20:30
  • The question seems to be _why_ is it escaped and a one-liner. – John Dvorak Dec 06 '12 at 20:32
  • @JanDvorak I would think if that were the case OP would have asked "why are forward slashes escaped," not "why are there both forward and backward slashes" – Brian Driscoll Dec 06 '12 at 20:33
  • 2
    they seem to escape forward slashes here. And this answer here clarifies that it's not really required: http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped ..... Still not sure about 1 line??? windows/linux compatibility? – Ryan Eckert Dec 06 '12 at 20:34
  • @RyanEckert I was just about to add that link to my answer - It looks like PHP's json encoding implementation does it. The fact that it's on one line is likely an artifact of the same encoding function. – Brian Driscoll Dec 06 '12 at 20:35
  • yeah. imho - you right. Since it autolatically generated it would make sense not to include PHP_EOL, since it's unknown at that that what platform this will be used on. – Ryan Eckert Dec 06 '12 at 20:40